Careeroza
HTTP Methods
Request and Response
A browser or mobile app (the client) sends an HTTP request to your API (the server). The server sends back an HTTP response. Every request has a method, a URL, headers and sometimes a body.
| Method | Meaning | ShopEase example | Has body? |
|---|---|---|---|
| GET | Read data | GET /products | No |
| POST | Create something | POST /products | Yes |
| PUT | Replace a whole resource | PUT /products/7 | Yes |
| PATCH | Change some fields | PATCH /products/7 | Yes |
| DELETE | Remove | DELETE /products/7 | Usually no |
Try It with curl
Example
-X sets the method, -H adds a header, -d sends a body, -i shows response headers.
curl -i -X POST http://localhost:3000/products \
-H "Content-Type: application/json" \
-d '{"name":"Noise ColorFit Pro","price":2999,"stock":40,"category":"wearables"}'Example output
HTTP/1.1 201 Created
Content-Type: application/json; charset=utf-8
{"id":11,"name":"Noise ColorFit Pro","price":2999,"stock":40,"category":"wearables"}Tip: GET, PUT and DELETE are idempotent: sending the same request twice has the same effect as once. POST is not: two POSTs create two products.