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
| Method | Action | 
|---|---|
| GET | Retrieve | 
| POST | Create | 
| PUT | Replace | 
| PATCH | Partial update | 
| DELETE | Remove | 
Understanding and using these methods properly is key to building and consuming RESTful APIs.
โ Learn More: