public class Startup
{
// ...
public void ConfigureServices(IServiceCollection services)
{
// ...
services.AddNSerializer();
// ...
}
// ...
}
[ApiController]
[Route("[controller]")]
public class DemoController : ControllerBase
{
private readonly NSerializer _serializer;
public DemoController(NSerializer serializer)
{
_serializer = serializer;
}
[HttpGet("ascreated")]
public ActionResult AsCreated()
{
return _serializer.SerializeAndCreated(new Demo(), "created_group");
}
[HttpGet("asok")]
public ActionResult AsOk()
{
return _serializer.SerializeAndOk(new Demo(), "ok_group");
}
}
More documentation and resources at webBeta NSerializer repository.