REST API

An architectural style for building web APIs using HTTP methods and stateless communication.

REST (Representational State Transfer) is an architectural style for designing networked applications. RESTful APIs use HTTP methods to perform operations on resources.

REST Principles

  • Stateless: Each request contains all needed information
  • Client-Server: Separation of concerns
  • Uniform Interface: Consistent resource naming
  • Cacheable: Responses can be cached

HTTP Methods in REST

MethodPurposeExample
GETRead dataGET /users
POSTCreate newPOST /users
PUTUpdate/ReplacePUT /users/1
PATCHPartial updatePATCH /users/1
DELETERemoveDELETE /users/1

Code Examples

REST Endpoints

GET    /api/users      - List all users
GET    /api/users/1    - Get user by ID
POST   /api/users      - Create user
PUT    /api/users/1    - Update user
DELETE /api/users/1    - Delete user