Explore Topics

REST Concepts

REST (Representational State Transfer) is an architectural style for building scalable web services. It uses simple HTTP requests to perform CRUD operations (Create, Read, Update, Delete) on resources.

Resources

In REST, a resource is any piece of data or entity that you want to expose through your web service. Think of resources as objects in the real-world customers, products, orders, etc.

Each resource is exposed via a URI (Uniform Resource Identifier).

For example,

This URI might represent the user with ID 101.

HTTP Methods

RESTful APIs use standard HTTP methods to define what action should be performed on a resource. These map directly to CRUD (Create, Read, Update, Delete) operations.

HTTP Method Action Description
GET Read Retrieve resource(s)
POST Create Add a new resource
PUT Update/Replace Fully update a resource
PATCH Partial Update Partially update a resource
DELETE Delete Remove a resource

For example,

  • POST /api/products to create a product
  • DELETE /api/products/1 to delete product 1

Status Codes

When a RESTful API processes a request, it responds with an HTTP status code to indicate success or failure. Clients use these codes to understand the result and handle it accordingly.

Status Code Meaning
200 OK Request succeeded
201 Created Resource successfully created
204 No Content Request succeeded, no response body
400 Bad Request Invalid client request
404 Not Found Resource not found
500 Internal Server Error Server-side error