That 9 HTTP Request Methods are…

Dilshuppa
3 min read1 day ago

--

  1. GET
GET /api/employees/123
  • Description: Retrieves data from the server without modifying it.
  • Use case: Getting a specific resource (in this case, employee data) without making any changes to the data.
  • Response:
{
"id": 123,
"name": "John Doe",
"position": "Developer"
}

2. POST

POST /api/employees/department
  • Description: Sends data to the server to create a new resource. This data is included in the body of the request.
  • Use case: When creating a new entity, such as a department or an employee.
  • Request Body:
{
"departmentName": "HR",
"location": "Building 2"
}
  • Response:
{
"departmentId": 10,
"departmentName": "HR",
"location": "Building 2"
}

3. PUT

PUT /api/employees/123
  • Description: Used to update an existing resource by sending a complete replacement of the resource’s data.
  • Use case: If you want to update an employee’s information completely.
  • Request Body:
{
"id": 123,
"name": "John Smith",
"position": "Senior Developer"
}
  • Response:
{
"id": 123,
"name": "John Smith",
"position": "Senior Developer"
}

4. PATCH

PATCH /api/employees/123
  • Description: Similar to PUT but only updates the fields that are included in the request, rather than replacing the entire resource.
  • Use case: If you only need to change a small part of the resource, like updating the employee’s name.
  • Request Body:
{
"name": "Brii"
}
  • Response:
{
"id": 123,
"name": "Brii",
"position": "Developer"
}

5. DELETE

DELETE /api/employees/235
  • Description: Deletes a resource. This method will remove the resource, and further calls to the resource should result in a 404 (Not Found) status.
  • Use case: To delete a specific employee by their ID.
  • Response:
{
"status": "Employee 235 deleted successfully"
}

6. OPTIONS

OPTIONS /api/main.html/1.1
  • Description: Returns information about the allowed communication methods for the specified resource. It can help in determining what operations are allowed on a resource.
  • Use case: When you want to know what actions (GET, POST, PUT, etc.) are allowed for a specific resource.
  • Response:
{
"methods": ["GET", "POST", "DELETE"]
}

7. TRACE

TRACE /api/main.html
  • Description: A diagnostic method that sends the request back to the client exactly as it was received, often used for debugging purposes. It shows what intermediate servers or proxies did to the request.
  • Use case: When you want to trace the path the request took through the server to diagnose issues.
  • Response (The request is echoed back exactly as it was sent.)
TRACE /api/main.html

8. HEAD

HEAD /api/employees
  • Description: Similar to a GET request, but does not return the actual content of the resource, only the headers (metadata). It is mainly used to check if a resource is available or to inspect its metadata.
  • Use case: Checking if a resource exists or if it has changed without downloading the resource.
  • Response:
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 250
Last-Modified: Mon, 21 Dec 2024 14:00:00 GMT

9. CONNECT

CONNECT www.example.com:443 HTTP/1.1
  • Description: Used to establish a tunnel to the server, often used with HTTPS to securely connect to a server.
  • Use case: When setting up a secure connection, typically for HTTPS.
  • Response:
HTTP/1.1 200 Connection Established

#infoSec #cybersecurity #pentest #Security

--

--

No responses yet