REST API stands for Representational State Transfer. It provides standard HTTP methods to create an API and enables communication between frontend and backend.
GET method is used to fetch data from the server.
For example — getting all cart items.
POST method is used to create new data.
For example — user registration, where we send user details in the request body and create a new user.
PUT method is used to update the entire object.
We send the complete updated object.
For example — user profile update. If a user wants to update their name, email, and phone, we send all three fields even if only the name changed. The server replaces the entire object with the new data.
PATCH method is used to update only specific fields — not the entire object.
For example — updating only the status of an order.
DELETE method is used to remove data.
We pass the item ID and the server deletes it.
All APIs should return proper HTTP status codes.
2XX = SUCCESS ✅
200 OK — Request succeeded, data returned.
201 Created — New resource created (POST request successful).
4XX = CLIENT ERROR ❌ (Client's fault)
400 Bad Request — Invalid data sent (invalid email, missing field).
401 Unauthorized — No token or invalid token (user is not authenticated).
404 Not Found — API route doesn't exist (wrong URL).
5XX = SERVER ERROR ❌ (Server's fault)
500 Internal Server Error — Server crashed or an unhandled error occurred.