.NET Academy

HTTP & REST cheat sheet

Methods, status codes, headers and REST API conventions.

Methods

MethodMeaningSafeIdempotentTypical success
GETReadβœ“βœ“200
HEADHeaders onlyβœ“βœ“200
POSTCreate / actionβœ—βœ—201 + Location, or 202
PUTReplaceβœ—βœ“200 / 204
PATCHPartial updateβœ—usually βœ—200 / 204
DELETERemoveβœ—βœ“204
OPTIONSCapabilities / CORS preflightβœ“βœ“204

Status codes

CodeNameWhen
200OKSuccess with a body
201CreatedResource created β€” add Location
202AcceptedQueued for background processing
204No ContentSuccess, no body (DELETE, some PUT/PATCH)
301 / 308Moved PermanentlyURL changed for good
302 / 307Found / Temporary RedirectTemporary redirect (e.g. http β†’ https)
304Not ModifiedCached copy still valid (ETag / If-None-Match)
400Bad RequestMalformed or invalid input
401UnauthorizedNot authenticated β€” log in / send a token
403ForbiddenAuthenticated but not allowed
404Not FoundNo such resource (or hidden from this user)
405Method Not AllowedWrong method for this URL β€” add Allow
409ConflictDuplicate, or outdated version
415Unsupported Media TypeWrong Content-Type
422Unprocessable ContentWell-formed but semantically invalid
429Too Many RequestsRate limited β€” add Retry-After
500Internal Server ErrorUnhandled server bug
502 / 504Bad Gateway / Gateway TimeoutUpstream failed / too slow
503Service UnavailableOverloaded or down for maintenance

Headers

HeaderPurpose
Content-Type: application/jsonBody format
Accept: application/jsonDesired response format
Authorization: Bearer <token>Credentials
Cookie / Set-CookieSession state (Secure; HttpOnly; SameSite=Lax)
Cache-Control: max-age=60 / no-storeCaching rules
ETag / If-None-MatchConditional requests
LocationURL of a created resource or redirect target
Retry-AfterWhen to try again (429, 503)
Strict-Transport-SecurityHTTPS only (HSTS)
Access-Control-Allow-OriginCORS
Idempotency-KeySafe retries of POST

REST conventions

GET    /products?category=books&sort=-price&limit=20&after=abc   list (filter, sort, cursor)
GET    /products/42                                              one
POST   /products                                                 create
PUT    /products/42                                              replace
PATCH  /products/42                                              update fields
DELETE /products/42                                              delete
GET    /customers/7/orders                                       sub-collection
POST   /orders/42/cancellation                                   action as a resource
  • Nouns in URLs, plural collections, verbs = HTTP methods.
  • Errors as Problem Details (application/problem+json): type, title, status, detail, errors.
  • Paginate collections; version breaking changes (/v2/...); make retries safe.

Raw request and response

POST /api/orders HTTP/1.1
Host: shop.example
Content-Type: application/json
Authorization: Bearer eyJhbGciOi…
 
{"productId": 1, "quantity": 2}
HTTP/1.1 201 Created
Content-Type: application/json; charset=utf-8
Location: /api/orders/1001
 
{"id": 1001, "status": "pending"}