Library to share commonly used web api utilities and tools in Pinja projects.
To add very verbose logging about incoming request (body, query etc...) add following to startup and set loggging level as 'Debug'.
app.UseMiddleware<RequestLoggerMiddleware>();
Pagination utility that create nice paged response from given query:
[HttpGet("foo")]
public ActionResult<Paged<FooResponse>> Get([FromQuery] int page)
{
return Ok(Paged<FooResponse>.FromQuery(_context.Foos.Select(...), page));
}
Utility to implement common "orderBy" queries at web api based on response type properties:
[HttpGet("foo")]
public ActionResult<Paged<FooResponse>> Get(
[FromQuery] OrderByQueryString<FooResponse> orderBy)
{
return Ok(_context.Select(FooResponse.Projection).OrderBy(orderBy));
}
And documentation support c.OperationFilter<OrderByOperationFilter>();
to swagger gen configuration.
Simple helper methods to implement common search, filtering etc operations at web api:
[HttpGet("foo")]
public ActionResult<Paged<FooResponse>> Get(
[FromQuery] OrderByQueryString<FooResponse> orderBy,
[FromQuery] FooFilterObject? filterObject,
[FromQuery] string? search = null)
{
var eventQuery = _context.Events
.AsNoTracking()
.SearchWhen(search,
e => e.Foo.BarName.Contains(searchString),
e => e.Foo.BarAddress.Contains(searchString))
.FilterWhen(() => FooFilterObject != null, e => e.State == filterObject);
}