REST API

  • stands for REpresentational State Transfer
  • It is an architectural approach for communication purposes often used in various web services development
  • It is a stateless client-server model
  • These are fast web services as they consume less bandwidth and resources.
  • It uses HTTP verbs like GET, POST, DELETE, PUT and PATCH for CRUD (Create, Read, Update and Delete) operations.
  • It is data-driven, meaning that data is available as resources.
  • It only works on HTTP(S)
  • An API designed according to the principles of REST is called RESTful API

6 Architectural Constraints of RESTful API

  • Uniform Interface
    • Resource-Based
    • HATEOAS
  • Stateless
    • Server should not maintain the session state (data), For example: we cannot call one API to “save” information in a session and then call another API so that server implicitly retrieves the “saved” information in a session.
    • The client should send ALL the data representing the current state of the system
    • Statelessness enables greater availability since the server does not have to maintain, update or communicate that session state.
  • Cacheable
    • Every “response” should include if the response can be cacheable or not
  • Client-Server
  • Layered System
  • Code on Demand (optional)
    • servers can also provide executable code to the client
    • For example, server can send:
      • compiled components such as Java Servlets
      • Server-Side Scripts such as JavaScript.