What is REST API

REpresentational State Transfer (REST) is an architectural style that defines a set of constraints to be used for creating web services.

Features

  • A web API that obeys the REST constraints is informally described as RESTful.
  • REST is a software architectural style.
  • REST API is a way of accessing web services in a simple and flexible way without having any processing knowledge.
  • In a RESTful Web service, requests made to a resource’s URI elicit a response with a payload formatted in JSON, or other format.
  • supports JSON and XML languages.
  • Provides error information to the developer and the reason for the error
  • REST API’s are stateless
  • A uniform interface is crucial to ensure decoupling the client from server and allow independent evolution of the application.
  • REST operates entirely on the HTTP protocol
  • Optimized Code Encapsulation

REST constraints (principles)

  • client–server architecture,
  • statelessness,
  • cacheability,
  • use of a layered system,
  • support for code on demand,
  • and using a uniform interface.

These principles must be followed for the system to be classified as RESTful.

The classic example of a non-RESTful system using HTTP is something which treats HTTP as if it was a transport protocol, and with every request sends a POST of data to the same URI which is then acted upon in an RPC-like manner, possibly with the connection itself having shared state. For example, GraphQL is not RESTful.

REST and CORS

Some terms

  • RESTful Web services allow the requesting systems to access and manipulate textual representations of Web resources by using a uniform and predefined set of stateless operations.
  • SOAP is a protocol. Unlike SOAP-based Web services, there is no “official” standard for RESTful Web APIs. This is because REST is an architectural style. It is not protocol.
  • Swagger is an Interface Description Language for describing RESTful APIs expressed using JSON. Swagger is used together with a set of open-source software tools to design, build, document, and use RESTful web services. Swagger includes automated documentation, code generation (into many programming languages), and test-case generation.
  • HTTP API: A RESTful API adheres ALL the REST constraints set out in its “format” documentation. A HTTP API is ANY API that makes use of HTTP as their transfer protocol. This means that even SOAP can be considered a HTTP API, as long as it will use HTTP for transport. RESTful API can based on HTTP or other protocol. Most HTTP APIs can be very close to becoming a truly RESTful API. Depend on the Glory of REST Model