Skip to main content

HTTP Methods Explained: GET, POST, PUT, PATCH & DELETE

Understand the HTTP methods behind REST APIs with simple explanations and practical FastAPI examples.

Updated 3 min readMarkdown

HTTP Methods Explained: GET, POST, PUT, PATCH & DELETE

Introduction

Whenever a frontend application communicates with a backend server, it needs to tell the server what it wants to do.

For example:

  • Get a list of users
  • Create a new account
  • Update a profile
  • Delete an order

HTTP methods provide a standard way to describe these actions.

If you're learning REST APIs or building backend applications with Python and FastAPI, understanding HTTP methods is essential.

In this article, we'll explore the five commonly used HTTP methods:

GET, POST, PUT, PATCH, and DELETE

We'll understand what each method does, when to use it, and how it works with practical FastAPI examples.


What Are HTTP Methods?

HTTP methods, also called HTTP verbs, indicate the intended action of an HTTP request.

For example:

GET /users

generally means:

Retrieve users.

While:

POST /users

generally means:

Create a new user.

The URL identifies the resource, while the HTTP method describes the operation.

A simple REST API might look like:

GET /users POST /users GET /users/10 PUT /users/10 PATCH /users/10 DELETE /users/10

Notice that the same /users resource can be used with different HTTP methods.

That's one of the important ideas behind RESTful API design.


Why HTTP Methods Matter in APIs

Using HTTP methods consistently makes APIs easier to understand and use.

Imagine an API where every operation uses POST:

POST /getUsers POST /createUser POST /deleteUser

A developer looking at this API has to learn the meaning of every custom endpoint.

A more conventional REST-style design would be:

GET /users POST /users DELETE /users/10

Now the intention is much clearer.

The method and URL work together to communicate the operation.


GET Method

The GET method is generally used to retrieve data from a server.

For example:

GET /users

could return a list of users.

A request for one particular user could look like:

GET /users/10

where 10 represents the user's ID.

Example Response

{
    "id": 10,
    "name": "Alex",
    "email": "alex@example.com"
}

Understanding Safe and Idempotent HTTP Methods

Two useful concepts in HTTP are safe and idempotent methods.

Understanding them helps you design APIs more correctly.

What Is a Safe Method?

A safe HTTP method is intended for retrieving information without requesting a change to the server's state.

GET is the most common example.

For example:

GET /users

This request asks the server to return users. It doesn't ask the server to create, update, or delete a user.

However, "safe" doesn't mean the server literally performs zero internal work. It means the method is intended to be read-only from the client's perspective.


What Is an Idempotent Method?

An idempotent operation produces the same intended result when the same request is performed multiple times.

For example, consider:

PUT /users/10

with:

{
    "name": "Alex",
    "email": "alex@example.com"
}

About the author

  • Software Engineering student passionate about building real-world projects and learning in public. Currently exploring Python, Data Structures & Algorithms, Web Development, Data Science, Machine Learning, and AI. This blog is where I document my learning journey, share projects, coding insights, and lessons learned while growing as a developer—one project and one article at a time.

No comments yet. Be the first to comment.