Rules to Better Web API - REST

Explore best practices for developing and managing your Web API using REST principles. This guide covers essential topics such as serialization of view models, documentation, versioning, and returning appropriate response codes.

  1. When building a simple API based on Entity Framework, It can be tempting to keep it simple and bind persistent entities directly to WebAPI output.

  2. Documenting your WebAPI is important but you don't want to spend a massive amount of time trying to keep documentation up to date. The solution is to use Swaggerand Swashbuckle.

  3. When integrating with external Web APIs which return a JSON response, there is a quick and easy way to generate classes to handle that response.

  4. When creating WebAPIs for your applications, it is useful to keep the naming consistent all the way from the back-end to the front-end.

  5. You can save time and reduce human error by automatically generating clients for your APIs.

  6. As an API provider, one of your most important tasks is to make sure that breaking changes will never occur in your API. Making breaking changes will make life difficult for the developers who depend on your service and can easily start causing frustration when things start to break.

  7. When the Web API creates a resource, it should include the URI of the new resource in the Location header of the response.

  8. Good error design is as important to the success of an API as the API design itself. A good error message provides context and visibility on how to troubleshoot and resolve issues at critical times.

  9. The use of correct response codes is a simple yet crucial step towards building a better WebAPI. In ASP.NET Core, by default the WebAPI framework sets the response status code to 200 (OK), regardless of whether the task succeed or an error occurred.

    You can save yourself countless hours of painful debugging , by specifying the correct response code.

  10. Client-side validation provides a great user experience but this must always be backed up by server-side validation.

per page
1 - 10 of 11 items
We open source.Loving SSW Rules? Star us on GitHub. Star