HTTP Methods GET POST PUT PATCH DELETE

Learn what the five core HTTP methods mean, when to use each one, and how they map to Axum routing for building backend services

Every time a browser loads a page, a mobile app fetches a news feed, or a form submits data to a server, the client sends a request that includes one crucial piece of information: the HTTP method. This page explains what GET, POST, PUT, PATCH, and DELETE mean, why they exist, and how you will see them appear in Axum routing code.

What an HTTP Method Does in a Request

Before any data travels between a client and a server, the client must declare what it wants to happen. This declaration travels as a single word in the very first line of an HTTP request.

Imagine you are handed a piece of paper with an instruction written at the top. The instruction could say "read this," "store this," "replace that," or "throw this away." Without that instruction, the person receiving the paper would not know what to do with the content on it.

An HTTP method is exactly that instruction. It tells the server what kind of operation the client wants to perform on a given resource. The resource is identified by the URL, and the method describes the intended action on that resource.

The five methods this page covers are the vocabulary used in almost every REST API built today. You will use them constantly when defining routes in Axum, so understanding each one independently matters.

Not an Axum Invention:

HTTP methods are defined by the HTTP specification itself, not by Axum or any other framework. Axum simply provides convenient functions named after these methods so you can wire routes to them. The meanings of GET, POST, PUT, PATCH, and DELETE are the same whether you use Axum, Express, Django, or plain HTTP.

Here is the full first line of a typical HTTP request:

GET /users HTTP/1.1

The word GET is the method. The path /users is the resource. The version HTTP/1.1 tells the server which version of the protocol the client speaks. Every HTTP request includes a method, and that method shapes how the server interprets everything else in the request.

Why One Method Is Not Enough

At first glance, you might wonder why we need five different words to talk to a server. Could the URL alone describe what should happen?

The problem is that the same resource often needs different operations at different times. Think about a list of users at /users. A client might want to retrieve the list. Another client might want to add a new user to that list. A third might want to remove a user. If the only signal was the URL, the server would have no way to tell these intentions apart.

HTTP solves this by separating the identifier from the action. The URL identifies the resource. The method identifies the action on that resource. This separation is powerful because it allows the same URL to support multiple behaviors cleanly.

Suppose you send GET /users and the server returns the full list of users. Now suppose you send POST /users with a JSON body describing a new user. The server knows to add that user to the list because the method says "post" (create), not "get" (read).

Without methods, you would need awkward URLs like /users/add, /users/delete, /users/update, and /users/view. Some early web services did exactly this. The problem is that URLs became inconsistent across services, and the same operation could have dozens of naming conventions. HTTP methods standardize the action vocabulary.

Here is a small comparison showing the difference:

GET /users          -> Return the list of users
POST /users         -> Add a new user to the list
GET /users/42       -> Return the single user with ID 42
DELETE /users/42    -> Remove the user with ID 42

The resource is /users or /users/42. The method tells the server what to do with that resource. This is the core mental model behind HTTP methods.

Right Mental Model:

If you can look at a URL like /users/42 and recognize that GET, PUT, and DELETE would each perform a different operation on it, you have understood the core idea of HTTP methods. The URL is the noun, the method is the verb.

GET Reads Existing Data

GET is the most common HTTP method you will encounter. Its purpose is to retrieve data from a server without changing anything on that server.

When you type a URL into a browser's address bar, the browser sends a GET request. When a frontend application fetches a list of products, it typically sends a GET request. When a mobile app pulls down the latest messages, it uses GET.

A GET request can include a body in theory, but the HTTP specification gives it no defined meaning, and most servers ignore it. The standard place to send additional information with a GET request is in the URL itself, most often through query parameters. The request body is left empty.

Here is a raw GET request to retrieve a user with ID 42:

GET /users/42 HTTP/1.1
Host: api.example.com
Accept: application/json

The response would contain a status code and a body with the user's data. The server does not modify any records, and repeating the same request produces the same result.

In Axum, you define a route for a GET method using the get function from the axum::routing module:

use axum::{routing::get, Router};
async fn get_user() -> &'static str {
    "Here is the user data"
}
let app = Router::new()
    .route("/users/42", get(get_user));

The handler function get_user runs only when an incoming request matches the path /users/42 and the method GET. If a client sends POST to that same path, Axum does not call this handler because the methods do not match. The path exists, so Axum answers with 405 Method Not Allowed, not 404 Not Found - 404 is only for paths that match no route at all.

You might wonder why a handler that reads data needs to be careful. The answer is that GET requests are expected to be safe. A "safe" method means it must not produce side effects on the server. Browsers, proxies, and crawlers may cache GET responses, send them multiple times, or prefetch them without asking. If a GET route accidentally deletes data or writes to a database, those automated systems could trigger unintended changes.

Never Modify State in GET:

A common beginner mistake is to place state-changing logic inside a GET handler because it feels convenient. For example, incrementing a view counter when a page is fetched. The problem is that browser prefetching, retries, or crawlers might trigger that logic many times without the user ever actually seeing the page. Keep GET handlers read-only.

POST Creates New Resources

POST tells the server to accept the data included in the request body and process it, usually by creating a new resource. It is the workhorse behind form submissions, user signups, comment creation, and file uploads.

The key characteristic of POST is that the client does not know the final URL of the resource it is creating. When you submit a form to create a new user, the request goes to /users, but the new user might end up at /users/57 or /users/103. The server decides the ID and returns the final URL in the response.

Here is a raw POST request creating a new user:

POST /users HTTP/1.1
Host: api.example.com
Content-Type: application/json
Content-Length: 47
{"name": "Alice", "email": "alice@example.com"}

The request body carries the data for the new user. The server receives it, generates an ID, stores the user, and responds with something like 201 Created along with the new resource's URL.

In Axum, you wire a POST route using the post function:

use axum::{routing::post, Router, Json};
use serde::Deserialize;
#[derive(Deserialize)]
struct CreateUser {
    name: String,
    email: String,
}
async fn create_user(Json(payload): Json<CreateUser>) -> String {
    format!("Created user {} with email {}", payload.name, payload.email)
}
let app = Router::new()
    .route("/users", post(create_user));

This example extracts the JSON body into a Rust struct using Axum's Json extractor. The handler then uses that data to form a response. In a real application, the handler would also insert the user into a database and return the new user's ID. That database logic belongs in a later chapter, but the method mapping is the same.

POST Is Not Idempotent:

Idempotent means repeating the same request produces the same result. POST is not idempotent. Sending the same POST request twice creates two users, not one. This is an intentional property: each POST request represents a new creation attempt.

One frequent beginner confusion is why the same path /users supports both GET and POST. The answer is that Axum routes are method-specific. A GET /users request hits one handler, while a POST /users request hits a different handler. The framework checks both the path and the method when deciding which handler to call.

PUT Replaces the Entire Resource

PUT tells the server to take the data in the request body and store it as the complete new state of the resource at the target URL. The word "complete" is critical here.

When you send a PUT request to /users/42, you are saying "replace everything about user 42 with this new data." The request body should contain all the fields that define that user, not just the fields you want to change. Any field omitted from the body is considered intentionally removed or set to a default value.

Here is a raw PUT request replacing user 42:

PUT /users/42 HTTP/1.1
Host: api.example.com
Content-Type: application/json
Content-Length: 59
{"name": "Alice Johnson", "email": "alice.new@example.com"}

The server receives this and completely overwrites the stored representation of user 42. If the user previously had a nickname field and the new body does not include it, that nickname is gone.

In Axum, PUT routes use the put function:

use axum::{routing::put, Router, Json};
use serde::Deserialize;
#[derive(Deserialize)]
struct UpdateUser {
    name: String,
    email: String,
}
async fn replace_user(Json(payload): Json<UpdateUser>) -> String {
    format!("Replaced user with name {} and email {}", payload.name, payload.email)
}
let app = Router::new()
    .route("/users/42", put(replace_user));

The handler extracts the JSON body and would in a real application replace the stored record with it.

PUT Deletes Fields You Omit:

The most consequential mistake with PUT is treating it like a partial update. If a user has fields name, email, and age, and you send a PUT body containing only name and email, the server will remove or reset the age field. This is why the complete-state rule matters. If you intend to update only one field, use PATCH instead.

PUT is idempotent. Sending the same PUT request five times produces the same result as sending it once, because the final stored state is always exactly what the body contains. This property makes PUT safer for network retries.

PATCH Applies a Partial Update

PATCH changes only the parts of a resource described in the request body, leaving everything else untouched. It solves the problem that makes PUT dangerous for partial updates.

When a client sends a PATCH request to /users/42 with {"email": "alice.new@example.com"}, the server updates only the email field. The name, age, and any other fields remain exactly as they were. This is the method you want when a user changes their profile picture, edits a single form field, or toggles a setting.

Here is a raw PATCH request updating just the email of user 42:

PATCH /users/42 HTTP/1.1
Host: api.example.com
Content-Type: application/json
Content-Length: 34
{"email": "alice.new@example.com"}

The server receives this, finds user 42, updates the email field, and leaves the rest of the record unchanged.

In Axum, PATCH routes use the patch function:

use axum::{routing::patch, Router, Json};
use serde::Deserialize;
#[derive(Deserialize)]
struct UpdateEmail {
    email: String,
}
async fn patch_email(Json(payload): Json<UpdateEmail>) -> String {
    format!("Updated email to {}", payload.email)
}
let app = Router::new()
    .route("/users/42", patch(patch_email));

The handler receives only the fields the client chose to send. In a real system, the server would merge this partial data with the existing stored record. That merging logic is a database operation rather than an HTTP concept, but the method semantics guide it.

The choice between PUT and PATCH depends on what the client knows and what it is trying to do. If the client has a complete, up-to-date representation of the resource and wants to ensure the server's copy matches it exactly, use PUT. If the client only knows which fields changed, use PATCH.

Here are the two shapes side by side, so the difference is visible in one place. First, the PUT body, which must contain every field:

{
    "name": "Alice Johnson",
    "email": "alice.new@example.com",
    "age": 30
}

And the PATCH body, which contains only the field that changed:

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

Read the two together and the rule becomes obvious: PUT carries the whole resource, PATCH carries only the difference. That is the entire distinction, and it is the reason mixing them up loses data.

DELETE Removes a Resource

DELETE tells the server to remove the resource identified by the URL. It is the simplest method in terms of semantics - there is usually no request body, and the response is typically a status code indicating success with no meaningful content.

Here is a raw DELETE request removing user 42:

DELETE /users/42 HTTP/1.1
Host: api.example.com

The server deletes the user and responds with 204 No Content or 200 OK. The resource no longer exists at that URL afterward.

In Axum, DELETE routes use the delete function:

use axum::{routing::delete, Router, http::StatusCode};
async fn delete_user() -> StatusCode {
    StatusCode::NO_CONTENT
}
let app = Router::new()
    .route("/users/42", delete(delete_user));

The handler returns StatusCode::NO_CONTENT, which maps to the HTTP status code 204. A 204 response means the server successfully processed the request and has no additional information to send back. This is a common pattern for DELETE handlers.

DELETE Is Idempotent:

Sending a DELETE request for the same resource twice produces the same end state. After the first request, the resource is gone. After the second request, the resource is still gone. Whether the server returns 204 or 404 on the second attempt is an implementation detail, but the final state is the same.

DELETE does not require a request body, and most servers ignore one if it is sent. Keep DELETE requests simple: the URL identifies what to remove, and no additional data is needed.

The Other Methods: HEAD, OPTIONS, TRACE, and CONNECT

The five methods above cover almost every API you will build, but HTTP defines a few more, and Axum has a routing function for each of them (head, options, trace, connect in axum::routing):

  • HEAD is exactly like GET, except the server must not send a body - only the status line and headers. Clients use it to check whether a resource exists, or to read headers like Content-Length, without downloading the body. It is safe and idempotent, like GET.
  • OPTIONS asks the server which methods and features a resource supports. The response usually carries an Allow header listing the methods. Browsers also send an OPTIONS request (a "preflight") before a cross-origin request to check what the server permits.
  • TRACE asks the server to echo the received request back to the client, mainly as a diagnostic tool. It is rarely used in application code.
  • CONNECT asks an intermediary (usually a proxy) to open a tunnel to another host, most commonly to carry TLS traffic through the proxy. You will almost never register a CONNECT route in an Axum application yourself.

303 See Other - Redirecting After a POST

One status code belongs with the methods discussion: 303 See Other. After a client submits a form with POST, the server often answers 303 with a Location header pointing at a results page. The client then follows that redirect with a GET, so refreshing the page does not resubmit the form. This is the POST/Redirect/GET pattern. Unlike 301 and 302, which leave it up to the client whether a POST stays a POST, 303 always switches the follow-up request to GET - that is its entire purpose. In Axum you return it with Redirect::to(url), which produces a 303 See Other response (there are also Redirect::temporary for 307 and Redirect::permanent for 308).

Safety and Idempotency in Plain Language

Two properties of HTTP methods are important enough to restate in simple terms.

A safe method does not change anything on the server. GET is safe. You can send the same GET request a hundred times and the server's data stays exactly the same.

An idempotent method produces the same result no matter how many times you send the same request. GET, PUT, and DELETE are idempotent. PATCH can be idempotent depending on how it is implemented, but the HTTP specification does not guarantee it. POST is not idempotent.

Here is the summary:

MethodSafeIdempotentTypical Purpose
GETYesYesRead data
POSTNoNoCreate data
PUTNoYesReplace data
PATCHNoSometimesUpdate partially
DELETENoYesRemove data

This table is worth internalizing because it guides how you structure APIs and why certain methods behave the way they do.

Check Your Understanding:

If you can explain why DELETE is idempotent but POST is not, you have grasped the core difference. DELETE removes the same thing twice - the result is "gone" either way. POST creates a new thing each time - the result is "two things exist" after two requests.

How Axum Maps Methods to Handlers

At this point you understand what each method means semantically. The next step is to see how Axum turns those meanings into runnable code.

Axum's Router uses method-specific function names to register handlers. The five functions you will use are get, post, put, patch, and delete, all from the axum::routing module. Each one takes a handler function as an argument and returns a route that matches only requests with that method.

Here is a complete Axum application showing all five methods mapped to the same resource:

src/main.rs
use axum::{
    routing::{get, post, put, patch, delete},
    Router,
    Json,
    http::StatusCode,
};
use serde::Deserialize;
#[derive(Deserialize)]
struct UserInput {
    name: String,
    email: String,
}
async fn list_users() -> &'static str {
    "Returning the list of all users"
}
async fn create_user(Json(payload): Json<UserInput>) -> String {
    format!("Creating user {}", payload.name)
}
async fn replace_user(Json(payload): Json<UserInput>) -> String {
    format!("Replacing user with data for {}", payload.name)
}
async fn patch_user(Json(payload): Json<UserInput>) -> String {
    format!("Partially updating user {}", payload.name)
}
async fn delete_user() -> StatusCode {
    StatusCode::NO_CONTENT
}
#[tokio::main]
async fn main() {
    let app = Router::new()
        .route("/users", get(list_users).post(create_user))
        .route("/users/42", put(replace_user).patch(patch_user).delete(delete_user));
    let listener = tokio::net::TcpListener::bind("0.0.0.0:3000")
        .await
        .unwrap();
    axum::serve(listener, app).await.unwrap();
}

The first route maps GET /users to list_users and POST /users to create_user. The second route maps PUT, PATCH, and DELETE to three different handlers at the same path /users/42. Axum inspects the incoming request's method and dispatches to the matching handler. Run it and try each method with curl: a GET to /users lists users, a POST with a JSON body creates one, and a DELETE to /users/42 answers 204 No Content.

Chaining Methods on One Path:

When you chain method functions on a single .route() call, all of them share the same path. This is convenient, but each handler's return type must implement IntoResponse - Axum converts every return value into an HTTP response through that trait, which is why a string and a status code can sit on the same route.

For now, the key vocabulary is that get, post, put, patch, and delete are method-specific route constructors whose names directly mirror the HTTP methods you learned here.

Common Mistakes and Misconceptions

Several pitfalls trip up beginners when they first work with HTTP methods. Naming them explicitly helps you avoid them.

The first mistake is thinking that the URL alone determines what a server does. A URL like /users is just an identifier. Without a method, there is no action. Two requests to the same URL with different methods can and should produce completely different behaviors.

The second mistake is using POST for everything. Some tutorials from the early web era taught developers to use POST for any non-read operation, including updates and deletions. This works technically, but it discards the semantic clarity that HTTP methods provide. Using PUT, PATCH, and DELETE where they belong makes APIs predictable and self-documenting.

The third mistake is confusing PUT with PATCH and then losing data. A developer who sends a partial payload with PUT intending to update one field will accidentally overwrite all the other fields. The fix is to recognize that PUT means full replacement and to use PATCH when only some fields change.

The fourth mistake is modifying server state inside a GET handler. This violates the safety expectation of GET and can cause duplicate side effects when browsers or proxies prefetch or retry requests.

The fifth mistake is sending a request body with GET or DELETE and expecting the server to honor it. While the HTTP specification technically allows bodies on some methods, most servers and frameworks ignore them for GET and DELETE. The convention is to keep bodies on GET and DELETE empty and to pass additional information through the URL or query string for GET, or not at all for DELETE.

The PUT vs PATCH Data Loss Trap:

This is the most consequential beginner mistake because it causes real user data loss. Sending {"email": "new@example.com"} with PUT to a user that also has a name and age will overwrite the entire record, losing the name and age. If your intent is to update just the email, the request must use PATCH. There is no safety net - the server cannot tell that you meant PATCH when you sent PUT.

The sixth misconception is thinking that the method determines the response format. A GET request can return JSON, HTML, plain text, or binary data. A DELETE request can return JSON or nothing at all. The method constrains the action, not the content type of the response.

Summary

The five methods covered here form the core action vocabulary for HTTP resources. GET reads without side effects. POST creates new resources and is neither safe nor idempotent. PUT replaces a resource completely and is idempotent. PATCH updates a resource partially. DELETE removes a resource and is idempotent. The less common methods - HEAD, OPTIONS, TRACE, and CONNECT - and the 303 See Other redirect fill in the gaps around them.

The most important insight to carry forward is the separation of identifier and action. A URL points to a resource, and the HTTP method describes what to do with it. This separation is what makes REST APIs predictable and why frameworks like Axum can route by method and path together.

When you see get, post, put, patch, and delete in Axum routing code, you now know they are not just function names. They are direct mirrors of HTTP semantics, each with specific expectations about safety, idempotency, and what the server should do with the request.