Bird
Raised Fist0
Rest APIprogramming~10 mins

Why HTTP methods define intent in Rest API - Visual Breakdown

Choose your learning style10 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.

Practice

(1/5)
1. Which HTTP method is used to retrieve data from a server without changing it?
easy
A. GET
B. POST
C. DELETE
D. PUT

Solution

  1. Step 1: Understand the purpose of HTTP methods

    GET is designed to request data without modifying it, making it safe and idempotent.
  2. Step 2: Match method to action

    Since the question asks for retrieving data without changes, GET fits perfectly.
  3. Final Answer:

    GET -> Option A
  4. Quick Check:

    Retrieve data = GET [OK]
Hint: GET is for reading data, no changes made [OK]
Common Mistakes:
  • Confusing GET with POST
  • Thinking DELETE retrieves data
  • Using PUT to fetch data
2. Which of the following is the correct syntax to update a resource using HTTP methods?
easy
A. GET /resource/123
B. DELETE /resource/123
C. POST /resource/123
D. PUT /resource/123

Solution

  1. Step 1: Identify the method used for updating

    PUT is the HTTP method used to update or replace a resource at a specific URL.
  2. Step 2: Check the syntax correctness

    PUT /resource/123 correctly targets the resource with ID 123 for update.
  3. Final Answer:

    PUT /resource/123 -> Option D
  4. Quick Check:

    Update resource = PUT [OK]
Hint: PUT updates existing resources fully [OK]
Common Mistakes:
  • Using GET to update
  • POST is for creating, not updating
  • DELETE removes, not updates
3. What will be the expected result of this HTTP request?
POST /users
{
  "name": "Alice",
  "age": 30
}
medium
A. Create a new user named Alice
B. Delete user Alice
C. Update existing user Alice's age
D. Retrieve user data for Alice

Solution

  1. Step 1: Identify the HTTP method used

    POST is used to create new resources on the server.
  2. Step 2: Analyze the request body

    The JSON data contains user details, indicating creation of a new user named Alice.
  3. Final Answer:

    Create a new user named Alice -> Option A
  4. Quick Check:

    POST with data = Create new resource [OK]
Hint: POST adds new data, not fetch or delete [OK]
Common Mistakes:
  • Thinking POST retrieves data
  • Confusing POST with PUT for update
  • Assuming POST deletes data
4. You want to remove a user with ID 45 using an HTTP request, but the request POST /users/45 is not working. What is the correct method to use?
medium
A. GET
B. PUT
C. DELETE
D. PATCH

Solution

  1. Step 1: Understand the intent of the request

    The goal is to remove (delete) a user, so the method must express deletion.
  2. Step 2: Choose the HTTP method for deletion

    DELETE is the standard method to remove a resource identified by a URL.
  3. Final Answer:

    DELETE -> Option C
  4. Quick Check:

    Remove resource = DELETE [OK]
Hint: DELETE removes resources, POST does not [OK]
Common Mistakes:
  • Using POST to delete
  • Confusing PATCH with DELETE
  • Trying GET to remove data
5. You have an API where PATCH /profile/123 updates only the email field of a user profile, while PUT /profile/123 replaces the entire profile. Why is it important to choose PATCH over PUT when updating just one field?
hard
A. PATCH is faster because it sends less data
B. PUT can accidentally erase other fields if not included
C. PATCH creates a new profile instead of updating
D. PUT is only for deleting resources

Solution

  1. Step 1: Understand the difference between PUT and PATCH

    PUT replaces the entire resource, so missing fields get erased. PATCH updates only specified fields.
  2. Step 2: Analyze the risk of using PUT for partial updates

    If you use PUT but omit some fields, those fields may be removed unintentionally.
  3. Final Answer:

    PUT can accidentally erase other fields if not included -> Option B
  4. Quick Check:

    Partial update safe = PATCH, full replace risk = PUT [OK]
Hint: Use PATCH for partial updates to avoid data loss [OK]
Common Mistakes:
  • Thinking PATCH creates new resource
  • Believing PUT only deletes
  • Assuming PATCH sends no data
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard