JSON API is a specification for how a client should request that resources be fetched or modified, and how a server should respond to those requests.
JSON API is designed to minimize both the number of requests and the amount of data transmitted between clients and servers. This efficiency is achieved without compromising readability, flexibility, or discoverability.
The current version of JSON API is 1.0. and will always be backward compatible. And JSON API requires the use of the JSON API media type application/vnd.api+jsonfor exchanging data.
- services.AddJsonApi<AppDbContext>();
- public class ArticlesController : JsonApiController<Article>
- {
- public ArticlesController(
- IJsonApiContext jsonApiContext,
- IResourceService<Article> resourceService)
- : base(jsonApiContext, resourceService) { }
- }
- Class Customer{
- public string FirstName {get; set;}
- public string LastName {get; set;}
- }
- // Also There were doing un-necessary implemenation to make first letter in the attribute make Uppercase.
- // eg:- URL:- /api/articles?filter[firstname]=sam
- private List<FilterQuery> ParseFilterQuery(string key, string value)
- {
- var queries = new List<FilterQuery>();
- var propertyName = key.Split('[', ']')[1].ToProperCase();
- }
- // Atribute name look like FirstName, once they apply Propercase method
- var concreteType = typeof(TSource);
- var property = concreteType.GetProperty(filterQuery.FilteredAttribute.InternalAttributeName);
- if (property == null)
- throw new ArgumentException($"'{filterQuery.FilteredAttribute.InternalAttributeName}' is not a valid property of '{concreteType}'");
- // here it will throw you the exception because it is not able to find the Attribute name, hence your sending filter with lower case
-
- Install-Package VisionPlanner.JsonAPI -Version 1.1.1
- services.AddJsonApi(opt =>
- {
- opt.Namespace = "api/v1";
- opt.DefaultPageSize = 5;
- opt.IncludeTotalRecordCount = true;
- });
- public class JsonAPISuccessController : Controller
- {
- private readonly IJsonoutputService _jsonoutputService;
- public JsonAPISuccessController(IJsonoutputService jsonoutputService)
- {
- _jsonoutputService = jsonoutputService;
- }
- }
- public class ModelService
- {
- private readonly IJsonoutputService _jsonoutputService;
- public ModelService(IJsonoutputService jsonoutputService)
- {
- _jsonoutputService = jsonoutputService;
- }
- }
- private int getTotalItems<TSource>(Expression expressions)
- {
- var usersCount = expressions != null ? MockingUserDetails().AsQueryable().Where(expressions.ToString()).ToList().Count() : MockingUserDetails().AsQueryable().ToList().Count();
- return usersCount;
- }
- public JsonParseObject getParseObject()
- {
- var oblDetails = _jsonoutputService.GetFilterExpression<UserDetails>();
- oblDetails.TotalCount = getTotalItems<UserDetails>(oblDetails.Expression);
- return oblDetails;
- }

Mokarom HossainPosted Dec 31, 2020, 10:37 AM
Hi thanks for this nice article. While experimenting I am getting the following error - 'Unable to resolve service for type 'Visionplanner.JsonAPI.Repository.IJsonoutputService' while attempting to activate 'TestJsonApi.Controllers.PersonsController'.'. Tried to add 'services.AddSingleton<IJsonoutputService, JsonoutputService>();' in my startup with no success. Can you please include what should be added in the Stratup.cs file to make this work?
Jayakrishna KPosted Nov 29, 2018, 12:49 AM
Just now i have release new version 2.0.0 to supported .Net Framework 4.7.1 and .NetCore 2.0.0