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.

MethodMeaningShopEase exampleHas body?
GETRead dataGET /productsNo
POSTCreate somethingPOST /productsYes
PUTReplace a whole resourcePUT /products/7Yes
PATCHChange some fieldsPATCH /products/7Yes
DELETERemoveDELETE /products/7Usually 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.