官术网_书友最值得收藏!

Introduction to REST

The REST acronym stands for Representational State Transfer. It's an architectural style and a design for network-based software. It describes how one system can communicate a state with another. This fits perfectly well into the microservice world. As you will remember from Chapter 3, Working with Microservices, the software applications based on the microservices architecture is a bunch of separated, independent services talking to each other.

There are some concepts in REST that we need to understand, before we go further:

  • resource: This is the main concept in the REST architecture. Any information can be a resource. A bank account, a person, an image, a book. A representation of a resource must be stateless
  • representation: A specific way a resource can be represented. For example, a bank account resource can be represented using JSON, XML, or HTML. Different clients might request different representations of the resource, one can accept JSON, while others will be expecting XML
  • server: A service provider. It exposes services which can be consumed by clients
  • client: A service consumer. This could be another microservice, application, or just a user's web browser running an Angular application, for example

As the definition says, REST is being used to transport those resource representations over the network. The representation itself is being created via some media type. Media types can be different. Some examples of media types include JSON, XML, or RDF. The JSON media type is widely accepted and probably the most often used. In our examples, we will also use JSON to communicate with our service. Of course, REST is not the only option for microservices communication; there are others, such as Google's very good gRPC, for example, which brings a lot of advantages such as HTTP/2 and protobuff. In the REST architecture, resources are manipulated by components. In fact, these components are our microservices. Components request and manipulate resources via a standard uniform interface. REST is not tied to any specific protocol; however, REST calls are most often being made using the most popular HTTP or HTTPS protocol. In the case of HTTP, this uniform interface consists of standard HTTP methods such as GET, PUT, POST, and DELETE.

REST is not tied to any specific protocol.

Before we start implementing our service that will respond to HTTP calls, it's worth knowing about the HTTP methods we are going to use. We are going to focus on them a little bit closer now.

主站蜘蛛池模板: 巴马| 卓资县| 谢通门县| 巩留县| 嵩明县| 崇明县| 洛扎县| 鄯善县| 泽州县| 炉霍县| 柳林县| 涟源市| 谢通门县| 措美县| 浪卡子县| 宁海县| 雷州市| 石嘴山市| 泰州市| 湛江市| 崇义县| 民县| 茶陵县| 武夷山市| 上栗县| 山西省| 富川| 台江县| 师宗县| 会昌县| 龙胜| 宜阳县| 香港| 孝感市| 云梦县| 麦盖提县| 镇平县| 晋城| 扎囊县| 阿拉善右旗| 襄汾县|