RESTful Web Services - Messages

RESTful web services use HTTP protocols as a means of communication between client and server. The client sends a message in the form of an HTTP request, and the server responds in the form of an HTTP response. This technique is called messaging. These messages contain message data and metadata, i.e. information about the message itself. Let's look at the HTTP Request and HTTP Response messages for HTTP 1.1.
HTTP request
An HTTP request consists of five main parts −
-
Verb − Specifies HTTP methods like GET, POST, DELETE, PUT, etc.
-
URI - Uniform Resource Identifier (URI) to identify the resource on the server.
-
HTTP Version - Specifies the HTTP version. For example, HTTP v1.1.
-
Request Header - Contains metadata for the HTTP request message in the form of key-value pairs. For example, client (or browser) type, client supported format, message body format, cache settings, etc.
-
The body of the request is the content of the message or a representation of the resource.
Verb − Specifies HTTP methods like GET, POST, DELETE, PUT, etc.
URI - Uniform Resource Identifier (URI) to identify the resource on the server.
HTTP Version - Specifies the HTTP version. For example, HTTP v1.1.
Request Header - Contains metadata for the HTTP request message in the form of key-value pairs. For example, client (or browser) type, client supported format, message body format, cache settings, etc.
The body of the request is the content of the message or a representation of the resource.
HTTP response
An HTTP response has four main parts:
-
Status/Response Code - Indicates the server status for the requested resource. For example, 404 means the resource was not found and 200 means the response is ok.
-
HTTP Version - Specifies the HTTP version. For example HTTP v1.1.
-
Response Header - Contains the metadata for the HTTP response message in the form of key value pairs. For example, content length, content type, response date, server type, etc.
-
The body of the response is the content of the response message or representation of the resource.
Status/Response Code - Indicates the server status for the requested resource. For example, 404 means the resource was not found and 200 means the response is ok.
HTTP Version - Specifies the HTTP version. For example HTTP v1.1.
Response Header - Contains the metadata for the HTTP response message in the form of key value pairs. For example, content length, content type, response date, server type, etc.
The body of the response is the content of the response message or representation of the resource.
example
As we explained in the RESTful Web Services - First Application chapter , let's put http://localhost:8080/UserManagement/rest/UserService/users into POSTMAN using a GET request. If you click the View button which is next to the Submit button and then click the Submit button, you can see the following output.
Here you can see that the browser sent a GET request and received an XML response body.