HTTP requests, methods and response status
Quick answer
HTTP exchanges requests and responses. A request specifies a resource and method; the response has a status, headers and sometimes a body.
How it works
GET retrieves a representation; POST submits data for processing; PUT commonly replaces a target representation; DELETE requests removal. The server defines its actual API contract. Safe methods are intended for retrieval without requested state changes; idempotence concerns repeated intended effects, not identical responses. 2xx means success, 4xx client error and 5xx server error. 204 has no body. The following constructed Responses are local models, not server replies.
Local examples
Run in a fresh browser document; no external network is needed. The actual ByteMind editor is unverified.
(async () => {const r=new Response(null,{status:204});console.log(r.status,r.ok,r.body===null);})()Expected console output:
204 true true204 is successful and has no body.
Run in a fresh browser document; no external network is needed. The actual ByteMind editor is unverified.
(async () => {const r=new Response("missing",{status:404});console.log(r.status,r.ok);})()Expected console output:
404 falseThe constructed response represents an HTTP error status.
Common mistakes
Do not assume a successful status means the expected data schema is valid. Never add a body to a 204 Response.
Guided practice
Classify 201, 204, 404 and 503; describe the intended method for reading an inventory item.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
HTTP requests, methods and response status — Knowledge Check
Apply the concept and reason about the example output.
Which method is intended for retrieval?
Which status requires a body-free response in this example?
Does idempotence require identical response bodies on repetition?
What is the expected console output of HTTP requests, methods and response status example 1?
(async () => {const r=new Response(null,{status:204});console.log(r.status,r.ok,r.body===null);})()What is the expected console output of HTTP requests, methods and response status example 2?
(async () => {const r=new Response("missing",{status:404});console.log(r.status,r.ok);})()