3 RESTful Principles and Guidelines

 

This chapter covers

  • Reviewing the six REST guiding constraints
  • Setting up and configuring CORS and caching techniques in ASP.NET Core
  • Understanding the role of reverse proxies and CDN services
  • Code on Demand use case example
  • Adopting a Uniform interface with HATEOAS capabilities
  • API documentation and versioning with Swagger / OpenAPI

Now that we have a minimal Web API boilerplate up and running, we are ready to review the REST properties and constraints that we've briefly introduced in Chapter 1 and see how they can be implemented in ASP.NET Core. More specifically, we'll add some built-in & third-party services and middleware to our existing MyBGList project to achieve a true RESTful status. This basically mean that we're going to introduce concepts such as separation of concerns, state management, caching, idempotency, API versioning, Hypermedia As The Engine Of Application State (HATEOAS), and Cross-Origin Resource Sharing (CORS).

Rest assured; we will not dwell too much on theory. The goal of this chapter is to learn how to put each of these topics into practice in ASP.NET Core.

By the end of the chapter, you will also be able to test your knowledge by solving some wrap-up exercises using the concepts covered and the programming techniques used.

The main goal we want to achieve is to understand the differences from a REST-based Web Application and a true RESTful Web API, paving the way for what will come next.

3.1 REST Guiding Constraints

3.1.1 Client-server approach

3.1.2 Statelessness

3.1.3 Cacheability

3.1.4 Layered system

3.1.5 Code on Demand

3.1.6 Uniform interface

3.2 API Documentation

3.2.1 Introducing OpenAPI

3.2.2 ASP.NET Core components

3.3 API Versioning

3.3.1 Understanding versioning

3.3.2 Should we really use versions?

3.3.3 Implementing versioning

3.4 Exercises

3.4.1 Cross-Origin Resource Sharing

3.4.2 Client-side Caching

3.4.3 Code on Demand

3.4.4 API Documentation and Versioning

3.5 Summary