How REST API related to HTTP

REST (Representational State Transfer) is an architectural style for building web services, while HTTP (Hypertext Transfer Protocol) is the underlying protocol used to transfer data over the web.

Relationship between REST and HTTP

  • RESTful APIs, which conform to the principles of REST, use HTTP as the standard protocol for communication between client and server.
  • In a RESTful API, the client sends an HTTP request to the server, and the server sends back an HTTP response. The request typically includes an HTTP method (such as GET, POST, PUT, or DELETE), a URI (Uniform Resource Identifier) that identifies the resource being requested, and an optional message body that contains additional data. The response typically includes a status code, which indicates the result of the request, and a message body that contains the requested data.
  • The HTTP methods used in a RESTful API correspond to the CRUD (Create, Read, Update, and Delete) operations that can be performed on a resource.
    For example, a GET request is used to read a resource, a POST request is used to create a new resource, a PUT request is used to update an existing resource, and a DELETE request is used to delete a resource.
  • RESTful APIs also use standard HTTP status codes to indicate the result of a request.
    For example, a 200 OK status code indicates that the request was successful, while a 400 Bad Request status code indicates that the request was invalid.

Conclusion

RESTful API is an architectural style that defines the guidelines for building web
services, and HTTP is the protocol that RESTful APIs use to transfer data between client and server.