REST & HTTP – REST APIs

Before you begin: Join our book community on Discord

Give your feedback straight to the author himself and chat to other early readers on our Discord server (find the “architecting-aspnet-core-apps-3e” channel under EARLY ACCESS SUBSCRIPTION).

https://packt.link/EarlyAccess

This chapter delves into the heart of web application communication–REST APIs. In today’s connected digital world, effective communication between different applications is paramount, and RESTful APIs play a pivotal role in facilitating this interaction.We start by exploring the basic fabric of the web: the HTTP protocol. We touch on the core HTTP methods such as GET, POST, PUT, and DELETE to see how they carry out CRUD (Create, Read, Update, Delete) operations in a RESTful context. We then turn our attention to HTTP status codes–the system’s way of informing clients about the status of their requests–and HTTP headers.Since APIs evolve and managing these changes without disrupting existing clients is a significant challenge, we look at different strategies for API versioning and the trade-offs involved with each.Then we learn about the Data-Transfer Object (DTO) pattern. Packaging data into DTOs can provide many benefits, from reducing the number of calls to better encapsulation and improved performance when sending data over the network.Finally, we also explore the importance of defining clear and robust API contracts, which ensures API stability. We discuss techniques for designing and documenting these contracts, ensuring they serve as practical guides for API consumers.By the end of this chapter, you’ll know how REST APIs work and will be ready to start building some using ASP.NET Core as we move further into our architectural journey in the next few chapters.In this chapter, we cover the following topics:

Let’s begin with REST.

REST & HTTP

REST, or Representational State Transfer, is a way to create internet-based services, known as web services, web APIs, REST APIs, or RESTful APIs. Those services commonly use HTTP as their transport protocol. REST reuses well-known HTTP specifications instead of recreating new ways of exchanging data. For example, returning an HTTP status code 200 OK indicates success, while 400 Bad Request indicates failure.Here are some defining characteristics:

While we could delve much deeper into the intricacies of REST APIs, the preceding characteristics serve as foundational knowledge, providing good enough knowledge to get started with RESTful services. Having navigated through these essentials, let’s shift our focus toward understanding how REST APIs harness the power of HTTP.

You may also like