0
0
Rest APIprogramming~10 mins

Why HTTP methods define intent in Rest API - Visual Breakdown

Choose your learning style9 modes available
Concept Flow - Why HTTP methods define intent
Client sends HTTP request
HTTP Method identifies intent
Server interprets method
Server performs action
Server sends response
Client receives response
The HTTP method in a request tells the server what action the client wants to perform, guiding the server's response.
Execution Sample
Rest API
GET /items/123 HTTP/1.1
Host: example.com

POST /items HTTP/1.1
Host: example.com
Content-Type: application/json

{"name": "New Item"}
Two HTTP requests: one GET to retrieve an item, one POST to create a new item.
Execution Table
StepHTTP MethodIntentServer ActionResponse Example
1GETRetrieve dataFetch item with ID 123200 OK with item data
2POSTCreate new dataAdd new item with provided data201 Created with new item info
3PUTUpdate dataReplace item with new data200 OK with updated item
4DELETERemove dataDelete item with ID 123204 No Content
5PATCHModify data partiallyUpdate item fields200 OK with updated fields
6-Unknown or unsupported methodReject request405 Method Not Allowed
💡 All HTTP methods define the intent; server acts accordingly or rejects unknown methods.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5Final
HTTP Method-GETPOSTPUTDELETEPATCH-
Intent-Retrieve dataCreate new dataUpdate dataRemove dataModify data partially-
Server Action-Fetch itemAdd itemReplace itemDelete itemUpdate fieldsReject unknown
Response-200 OK201 Created200 OK204 No Content200 OK405 Method Not Allowed
Key Moments - 3 Insights
Why does the server respond differently to GET and POST even if the URL is the same?
Because the HTTP method defines the intent. GET means retrieve data, POST means create data. See execution_table rows 1 and 2.
What happens if the client sends an HTTP method the server does not support?
The server rejects the request with a 405 Method Not Allowed response, as shown in execution_table row 6.
Why is DELETE method's response 204 No Content instead of 200 OK?
Because DELETE removes data and usually returns no content, indicating success without returning data. See execution_table row 4.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the server action when the HTTP method is PATCH?
AFetch item data
BUpdate item fields partially
CDelete item
DCreate new item
💡 Hint
Check execution_table row 5 under Server Action column.
At which step does the server respond with 201 Created?
AStep 2
BStep 4
CStep 1
DStep 6
💡 Hint
Look at execution_table row 2 under Response Example.
If the client sends a PUT request, what intent does the server recognize?
ARemove data
BCreate new data
CUpdate data
DRetrieve data
💡 Hint
See execution_table row 3 Intent column.
Concept Snapshot
HTTP methods define the client's intent in REST APIs.
Common methods: GET (read), POST (create), PUT (replace), PATCH (modify), DELETE (remove).
Server uses method to decide action and response.
Unknown methods get 405 Method Not Allowed.
This clear intent helps APIs be predictable and organized.
Full Transcript
When a client sends an HTTP request, the HTTP method tells the server what the client wants to do. For example, GET means the client wants to get or read data, while POST means the client wants to create new data. The server looks at the method and performs the matching action, like fetching, creating, updating, or deleting data. If the method is unknown or not supported, the server rejects the request with a 405 error. This way, HTTP methods define the intent clearly, making communication between client and server organized and predictable.