REST API Fundamentals

What is an API? API stands for Application Programming Interface. It is set of programming instructions and standards for accessing a Web-based software application or Web tool, it also defines interactions between multiple software intermediaries.

Types Of APIs? There are different types of APIs which include REST API, SOAP API, ASP.NET.

For the purpose of the article, we will focus on REST API.

What is REST? REST stands for "REpresentational State Transfer". REST is a Resource-Based API as it represents how resources are to be shared between the client and server.

Representation here doesn't mean the resource itself, it only means how the resources are shared. REST APIs do a lot of things including:

  1. They represent the resource state.

  2. They are how resources get manipulated.

  3. They represent how resources get transferred between the client and server.

  4. They are typically JSON or XML.

The 6 Constraints of REST API

  1. Uniform Interface
  2. Stateless
  3. Client-Server
  4. Cacheable
  5. Layered System
  6. Code on Demand

Uniform Interface REST API defines the interface between the client and the server. It simplifies and decouples the architecture of the system. This is fundamental to a RESTful Design which means: http verb (POST, PUT, GET, DELETE) URIs (resource name) HTTP response(status, body)

Stateless In the stateless constraint of REST API, the server does not contain client state. Each request contains self-descriptive messages and any session state is held on the client side.

Client- Server The client and Server run on a disconnected system and only share resources through the REST API.

Cacheable Server responses (representations) are cacheable. These cached responses can be Implicit, Explicit, Negotiable.

Layered System Client can't assume direct connection to server. There are always software or hardware intermediaries between client and server.

Code on Demand Sometimes the server can temporarily extend to the client.

Compliance with REST constraints allows for: Scalability, Simplicity, Modifiability, Visibility, Portability and Reliability.