Skip to content

Latest commit

 

History

History
106 lines (80 loc) · 3.67 KB

README.md

File metadata and controls

106 lines (80 loc) · 3.67 KB

Simplify.Web.Json

Nuget Version Nuget Download Build PackageLibraries.io dependency status for latest release CodeFactor Grade Platform PRs Welcome

Simplify.Web.Json is a package which provides JSON serialization/deserialization for Simplify.Web web-framework controllers using Newtonsoft.Json.

Quick Start

Sending JSON to client

If the controller returns Json response class object, then the Framework execution will be stopped, object will be parsed to JSON string and sent to client

public class MyController : Controller2
{
    public ControllerResponse Invoke()
    {
        ...
        return new Json(myObj);
    }
}

Getting JSON from client

Registering binder

public void Configuration(IApplicationBuilder app)
{
    ...
    HttpModelHandler.RegisterModelBinder<JsonModelBinder>();

    app.UseSimplifyWeb();
}

public void ConfigureServices(IServiceCollection services)
{
    ...
    HttpModelHandler.ModelBindersTypes.Clear(); // This is required to remove built-in JSON model binder (based on System.Text.Json)
    DIContainer.Current.RegisterJsonModelBinder();
    ...
}

Accessing model

Asynchronous
public class MyController : Controller2<MyModel>
{
    public async Task<ControllerResponse> Invoke()
    {
        await ReadModelAsync();

        Model.
    }
}
Synchronous

JSON string will be deserialized to the controller model on first model access

public class MyController : Controller2<MyModel>
{
    public ControllerResponse Invoke()
    {
        Model.
    }
}

Contributing

There are many ways in which you can participate in the project. Like most open-source software projects, contributing code is just one of many outlets where you can help improve. Some of the things that you could help out with are:

  • Documentation (both code and features)
  • Bug reports
  • Bug fixes
  • Feature requests
  • Feature implementations
  • Test coverage
  • Code quality
  • Sample applications

Related Projects

Additional extensions to Simplify.Web live in their own repositories on GitHub. For example:

License

Licensed under the GNU LESSER GENERAL PUBLIC LICENSE