A Structural Overview Of An API

In this article, I’m going to discuss the following topics related to an API.

  1. What is an API?
  2. What is the basic use of an API?
  3. What are the different types of API?
  4. What is a Restful API?
  5. What are the HTTP verbs related to an API?
  6. What are the HTTP status code related to an API?

What is an API?

API is more like an agreement or a contract of services between any application with distinct functions. Here, the contract of service referred as an application INTERFACE and application with distinct functions referred as an application PROGRAMS, and that’s how API stands for APPLICATION PROGRAMMING INTERFACE.

What is the basic use of an API?

API is mostly used for interaction( by transferring data ) between more than two applications followed by a request-response behaviour.

What are the different types of API?

There are two ways you can categorized an API.

  1. Based on architecture, for example
    • RPC ( Remote Procedure Call ), there are two variation  XML-RPC, JSON-RPC
    • SOAP ( Simple Object Access Protocol )
    • REST ( Representational  State Transfer )
    • GraphQL
  2. Based on availability, for example
    • Open API / Public API
    • Partner API
    • Internal API / Private API
    • Composite API

In today’s world most of the APIs are REST Driven or  RESTful ( based on REST  architecture ).

What is a Restful API?

There are six constraints in a REST API or a RESTful API. Any API can be a RESTful  API if it follows those six constraints.

  1. Uniform Interface -  An agreement that separates clients from the server. A resource( information returned by an API ) in the system should have only one logical URI but it should contain links (known as HATEOAS) pointing to relative URIs to fetch related information.
  2. Client- Server - Client and the Server must be able to evolve separately without depending upon each other.
  3. Stateless - The server will not store anything about the latest request that the client made. It will treat every request as a new one. Here the client is responsible for managing the state of the application.
  4. Layered System - A application architecture should be distributed in multiple layers but each layer doesn't need to know anything about any other layer other than the intermediate one.
  5. Cacheable  - The main function of that constraint is to increase the performance of the application by storing frequently used data either on the client-side or the server-side.
  6. Code on demand(optional) - Most of cases its optional. But it works by returning an executable code to support a part of your application.

What are the HTTP verbs related to an API?

HTTP verbs mainly use to tell the server what to do with the data identified by the URL. There are 5 most common HTTP verbs and their uses as follows.

  1. POST - Create new resource ( C )
  2. GET - Read resources ( R )
  3. PUT  -  Update/Replace existing resource  ( E )
  4. PATCH - Update/Modify existing resource
  5. DELETE - Delete resources ( D )

It almost similar to the CRUD functionality with different verbs.

What are the HTTP status code related to an API?

HTTP status code divided into 4 segments and each segment has their own functionality.

  1. 2xx series related to Successful Request.
    • 200 - Successful
    • 201 - Resource Created
    • 204 - Resource Updated
  2. 3xx series related to Redirection
    • 301 - Permanent redirection ( possible to change HTTP verb )
    • 307 - Temporary redirection ( can’t change HTTP verb )
    • 308 - Permanent redirection ( can’t change HTTP verb )
  3. 4xx series related to Client Error
    • 400 - Bad request
    • 401 - Wrong credentials ( unauthorized )
    • 403 - Lack of  authorization ( forbidden )
    • 404 - Resource not exist
    • 405 - HTTP verb mismatch
    • 422 - Send data invalid
  4. 5xx series related to Server Error
    • 500 - Internal Server error
    • 501 - If server don’t know how to handle the request
    • 502 - Bad Gateway
    • 503 - Service is down for maintenance
    • 504 - Gateway timeout


Similar Articles