A Practical Web API Validation Strategy

In my last post I wrote about how you can leverage JSON Schema to do Web API validation. The main benefit is that the API can expose the schema as an API resource, clients of the API can consume the schema and execute it on their end against any data. The benefit of doing API validation like this is that the client does not need to duplicate any validation logic, they only need to execute the schema....

October 13, 2021 · Yunier

A Better Web API Validation Strategy

As an API developer, you will eventually need to determine how to handle data validation. The .NET ecosystem offers a few options, the first option, validation attributes, can be used to annotate how a model should be validated. Validation attributes are great, they don’t require any external dependencies, you can specify error messages, create your own custom validator, validate against many data types. For example, take the following Movie class, notice how the properties have been annotated with validation rules....

October 9, 2021 · Yunier

JSON:API - Creating New Resources

So far in my JSON:API series I’ve covered the home resource, adding your own resource, adding an exception handling middleware and how to expose relationship between resources. For the today’s post, I would like to cover creating resources. I will update the chinook project by allowing POST request on the customers collections to add new customers. To get started, the customer controller needs to have a method that will accept the incoming POST request....

August 8, 2021 · Yunier

Problem Details for HTTP APIs

One of the many benefits of working with JSON:API and GraphQL is having a standardize way to communicate failures to a client. If you are not working with a spec like JSON:API or GraphQL, then you are in the hands of the developer that built the API and every developers implements error handling differently. Almost every HTTP API that I've consumed implements errors differently. Can we just agree to use Problem Details and be done with it?...

May 11, 2021 · Yunier

JSON:API - Exposing The Customer Resource

This will be my third blog post on JSON:API in .NET Core. I plant to add Customer as an API resource, but before we get too deep on the code, I would like to review the Chinook database project. To do that I’m going to import Chinook.db into DB Browser for SQLite to see all available entities. As you can see we have quite a few entities, for this blog post I will concentrate on the customers entity....

October 30, 2020 · Yunier