Published on

REST API - Introduction

Authors
  • avatar
    Name
    Iraianbu A
    Twitter

Table of Contents

  1. Introduction
  2. API Fundamentals
  3. API Classifications
  4. REST Principles
  5. Challenges
  6. References

Introduction

Introduction

REST (Representational State Transfer) is a architectural style for designing networked applications that leverages the HTTP protocol for communication between systems over the internet. REST APIs utilize standard HTTP methods like GET, PUT, POST, and DELETE to perform operations on resources, making them intuitive and widely compatible.

REST API

Source : https://www.postman.com/what-is-an-api/

API Fundamentals

An Application Programming Interface (API) serves as a mediator between different software applications, enabling them to communicate and exchange data without direct access to each other's internals. APIs define the structure of requests and responses, creating standardized methods of interaction.

Examples of APIs

  • Weather APIs
  • Uber driver APIs
  • DOM (Document Object Model) APIs

API Classifications

Access Level

  • Public APIs: Open for any developer to use
  • Private APIs: Restricted to internal use within organizations

Communication Methods

  • REST: Resource-based approach using HTTP methods
  • SOAP: Protocol using XML for structured message exchange
  • GraphQL: Query language allowing clients to request specific data
  • gRPC: High-performance RPC framework using protocol buffers

Data Format

  • JSON: Lightweight, human-readable format
  • XML: More verbose but highly structured
  • Plain text: Simple string responses

Processing Approach

  • Real-time: Immediate processing and response
  • Batch Processing: Handling multiple requests together

Authentication Methods

  • API Keys: Simple token-based access
  • OAuth: Token-based authorization framework
  • JWT: Self-contained tokens with encoded claims

REST Principles

Client-Server Architecture

A separation of concerns where clients send requests to servers that process them and return appropriate responses. This separation allows each component to evolve independently.

Statelessness

Each request from client to server must contain all information needed to understand and process the request. The server doesn't store client session information between requests, simplifying server implementation and improving scalability.

Uniform Interface

Standardized methods of interaction through:

  • Consistent resource identification via URLs
  • Standard HTTP methods (GET, POST, PUT, DELETE)
  • Self-descriptive messages
  • Hypermedia as the engine of application state (HATEOAS)

Cacheability

Responses must define themselves as cacheable or non-cacheable to prevent clients from reusing stale data and improve performance by reducing redundant requests.

Layered System

Architecture allowing intermediaries (proxies, gateways, load balancers) between client and server without affecting the interface or functionality.

Code on Demand (Optional)

Servers can temporarily extend client functionality by transferring executable code.

Challenges

  • Error Handling
  • Versioning
  • Pagination
  • Security

References

  1. Master REST APIs: The Backbone of Modern Web Applications
  2. Algomaster
  3. GeeksforGeeks