REST (Representational State Transfer) is an HTTP-based architecture for web services. RESTful APIs use standard HTTP methods (GET, POST, PUT, DELETE) to interact with resources, usually in JSON format.
HTTP Methods in REST API
Method |
Purpose |
Example URL |
GET |
Retrieve data |
GET /users/1 |
POST |
Create a new resource |
POST /users |
PUT |
Update a full resource |
PUT /users/1 |
PATCH |
Partially update a resource |
PATCH /users/1 |
DELETE |
Remove a resource |
DELETE /users/1 |
Best Practices
- Use Plural Nouns for Resources
- Use Path Parameters for Specific Resources
GET /users/123
✅ (Retrieve user with ID=123)
- Use Query Parameters for Filtering
GET /users?age=25
✅ (Retrieve users aged 25)
- Use Proper HTTP Status Codes
Code |
Meaning |
200 OK |
Successful request |
201 Created |
Resource successfully created |
400 Bad Request |
Invalid request format |
401 Unauthorized |
Missing authentication token |
404 Not Found |
Resource does not exist |
500 Internal Server Error |
Server-side error |