REST

REST is an architectural style that describes best practices for exposing web services over HTTP. REpresentational State Transfer (REST), was coined by Roy Fielding. It is based on HTTP as an application protocol. REST is not just a means of transport, a framework, or specification, but instead is a style that emphasizes scalability.

Nowadays, RESTful is a popular style for developing APIs for enterprise application. REST is an architecture style and is used in the Inter-Process Communication (IPC) mechanism that uses HTTP. A resource is a key concept in REST architecture. It represents a business object such as an account or a customer; it can also represent a collection of business objects. In REST style, HTTP verbs are used as the actions for manipulating resources, and these actions are referenced using a URL.

REST services expose resources through URIs, such as the following: https://www.dineshonjava.com/book-shop/books/123456789. Resources support a limited set of operations such as GET, PUT, POST, and DELETE in the case of HTTP. All of these have well-defined semantics. For example, we can update the order PUT by calling /orders/123, but we can't update POST using /order/edit?id=123.

In REST services, clients can request a particular representation. Resources can support multiple representations, such as HTML, XML, or JSON, and representations of a resource can link to other resources. When using Hypermedia As The Engine of Application State (HATEOAS), the RESTful responses contain the links you need, just like HTML pages do.

RESTful services use a stateless architecture, so there is no HttpSession usage. The GET operations can be cached on URLs. REST provides looser coupling between the client and the server. HTTP headers and status codes communicate the result to clients.

REST provides a set of architectural constraints that, when applied as a whole, emphasize the scalability of component interactions, the generality of interfaces, independent deployment of components, and intermediary components to reduce interaction latency, enforce security, and encapsulate legacy systems.
– Roy Fielding, Architectural Styles and the Design of Network-based Software Architectures.

Let’s have a look at the following diagram, which explains what a synchronous REST call is:

In the preceding diagram, the ShopFrontUI web or mobile application requests a book order by making a POST request to the /book-order resource of the Order Service. The Order microservice handles this request by sending a GET operation to fetch information about the requested book with its ISBN number from the Book Service. If the requested book is available in the warehouse, the Order microservice creates an order for the customer and returns a 201 response to the ShopFrontUI or the mobile application.

Let’s now move on and have a look at the benefits of REST.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.235.225