Main REST API Requests Explained with Examples

When working with APIs, especially in web and backend development, you’ll encounter a set of standard HTTP methods used to interact with resources. These methods follow REST principles โ€” a common architectural style.

Let’s break down the most commonly used REST methods:


๐Ÿ” GET โ€” Retrieve Data

Use GET to request data from a server.

Example:

GET /users/123 HTTP/1.1
Host: example.com

This will fetch information about the user with ID 123.


โœ๏ธ POST โ€” Create Data

Use POST to create a new resource on the server.

Example:

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

{
  "name": "Alice",
  "email": "alice@example.com"
}

๐Ÿ“ PUT โ€” Replace Existing Data

Use PUT to fully replace an existing resource.

Example:

PUT /users/123 HTTP/1.1
Content-Type: application/json

{
  "name": "Alice Updated",
  "email": "alice.updated@example.com"
}

๐Ÿ”ง PATCH โ€” Partially Update Data

Use PATCH to update part of a resource.

Example:

PATCH /users/123 HTTP/1.1
Content-Type: application/json

{
  "email": "new.email@example.com"
}

โŒ DELETE โ€” Remove Data

Use DELETE to remove a resource.

Example:

DELETE /users/123 HTTP/1.1

๐Ÿ”š Summary

MethodAction
GETRetrieve
POSTCreate
PUTReplace
PATCHPartial update
DELETERemove

Understanding and using these methods properly is key to building and consuming RESTful APIs.

โ†’ Learn More: