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
  • Implementing code on demand with a use-case example
  • Adopting a uniform interface with HATEOAS capabilities
  • Adding API documentation and versioning with Swagger/OpenAPI

Now that we have a minimal web API boilerplate up and running, we’re ready to review the representational state transfer (REST) properties and constraints briefly introduced in chapter 1 and see how they can be implemented in ASP.NET Core. Specifically, we’ll add some built-in and third-party services and middleware to our existing MyBGList project to achieve true RESTful status. The chapter introduces 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 that we won’t dwell too much on theory. This chapter shows how to put these topics into practice in ASP.NET Core.

By the end of the chapter, you’ll be able to test your knowledge by solving some wrap-up exercises on the concepts and programming techniques discussed here. The main goal is to understand the differences between a REST-based web application and a true RESTful web API, paving the way for what comes 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?