Build JSON:API endpoints in ASP.NET Core.
JsonApiToolkit translates JSON:API query parameters (filter[], sort, include, fields[], page[]) into typed EF Core queries and shapes responses as spec-compliant documents, so your ASP.NET Core controllers stay short.
dotnet add package Intility.JsonApiToolkitRegister the toolkit in Program.cs:
builder.Services.AddJsonApiToolkit();Derive controllers from JsonApiController and let JsonApiQueryAsync handle the request:
public class BooksController : JsonApiController
{
private const string ResourceType = "book";
[HttpGet]
[AllowedIncludes("author", "publisher")]
public async Task<IActionResult> GetAllAsync()
{
return await JsonApiQueryAsync(_dbContext.Books, ResourceType);
}
}Then call the endpoint with JSON:API query parameters:
GET /api/books?filter[title]=javascript&include=author&fields[book]=title,published&page[size]=10&sort=-published
- JSON:API documents - compliant
data/included/meta/links/errorsenvelope on every response - Filtering -
filter[field]=valuewith operators, nested paths, and filtering on included resources - Sorting -
sort=field,-otherwith multi-field and descending support - Pagination -
page[number]/page[size]with link generation, total counts, and clamping - Sparse fieldsets -
fields[type]=a,bto limit returned attributes per resource type - Included resources -
include=author,publisher.countrywith allowlisting via[AllowedIncludes] - EF Core integration - query operators translate directly to SQL via
IQueryable - Strict mode - return 404 for out-of-range pages and validate filter paths against allowed includes
Full documentation is at https://intility.github.io/json-api-toolkit/.