Skip to main content
ValyouValyou.

REST API

A type of API that uses standard HTTP methods and is designed around resources, making it simple and scalable.

A REST API (Representational State Transfer API) is an architectural style for building web services. It uses standard HTTP methods and is designed around resources (things like users, products, or orders), each identified by a URL.

Core Principles

REST APIs follow six key principles:

  1. Client-Server: The frontend and backend are separate and independent
  2. Stateless: Each request contains all the information needed to process it
  3. Cacheable: Responses can be cached to improve performance
  4. Uniform Interface: Consistent, predictable URL patterns and methods
  5. Layered System: Can have intermediary servers (load balancers, caches)
  6. Code on Demand (optional): Servers can send executable code to clients

HTTP Methods in REST

  • GET: Retrieve data (e.g., GET /users/123 returns user 123)
  • POST: Create new data (e.g., POST /users creates a new user)
  • PUT: Update existing data (e.g., PUT /users/123 updates user 123)
  • DELETE: Remove data (e.g., DELETE /users/123 removes user 123)

Example

To get a list of products from an e-commerce API:

GET https://api.store.com/products

The server responds with JSON data containing the products.

Why REST is Popular

REST APIs are simple, scalable, and work with any programming language. They're the standard for most web and mobile applications today.