Recent chats
ASKGEEZ Q&A GUIDETechnology & devices

When should an API request use GET rather than POST?

Quick answer

Use GET when you want to retrieve a resource without asking the server to change it. Use POST when you send data for the server to process, which may cause a state change or another effect. HTTP classifies GET as safe and idempotent; POST is not safe or idempotent by default. Check the API documentation because individual endpoints may follow specific conventions. [S1] [S2]

LET’S WORK THROUGH IT

The question, the details, the next step.

Question

I’m choosing a method for an API endpoint. What’s the basic rule for GET versus POST?

Geez

Start with what you want the server to do. Use GET to retrieve a representation of a resource. The URL and its query parameters can identify the data you want. For example, GET /products?category=books asks for product data in the books category. GET is meant for retrieval, not for requesting a change, and a GET request should not contain a body. [S1]

Use POST when you send data for the server to process. For example, POST /orders with an order body can submit order data. Processing may change state or have another effect, such as adding a resource. [S2]

In short: retrieve data → GET; send data for processing → POST. Then check that the endpoint’s documentation supports your choice.

Follow-up question

Can you compare their expected effects? I don’t want to choose based only on whether I have data to send.

Geez

Right: the important distinction is the operation, not just whether the request contains information.

  • GET — retrieval: Requests a representation of a resource. Query parameters can specify what to retrieve, as in GET /products?category=books. HTTP classifies GET as safe and idempotent. [S1]
  • POST — processing: Sends data for the server to process. That processing may change state or have another effect. HTTP does not classify POST as safe or idempotent by default. [S2]

Here, “safe” means GET is defined for retrieval rather than for requesting a change. “Idempotent” means repeating the same request has the same intended effect as making it once. Those are general HTTP semantics; they don’t establish exactly what any particular API endpoint does.

Follow-up question

Suppose I’m building a search endpoint. It receives a search term, but it doesn’t create anything. Is GET still a reasonable choice?

Geez

If the endpoint retrieves results and its API documentation supports that design, GET is a reasonable fit. The search term could be a query parameter, for example GET /products?search=notebook. That matches the general pattern of using query parameters to identify the data being requested. [S1]

Don’t decide from the word “search” alone. Check the API’s documented method, parameter names, and behavior. The general HTTP semantics don’t specify how a particular search endpoint works or what parameters it accepts. If the endpoint is documented to accept data for processing using POST, follow that documented convention.

Follow-up question

How do I make the choice consistently when designing or calling other endpoints?

Geez

Use this decision guide:

  1. Describe the operation: are you retrieving data, or sending data for processing?
  2. For retrieval, check whether the API documents GET and the query parameters to use. GET is not meant for requesting a change. [S1]
  3. For submitted data, check whether the API documents POST and what processing it performs. [S2]
  4. Before repeating a POST, check the endpoint documentation. POST is not idempotent by default, so an identical repeat may have additional effects. [S2]
  5. If the API’s documented method differs from the general pattern, follow its documentation.

For example, an API might document GET /products?category=books to retrieve products and POST /orders with an order body to submit order data. These hypothetical requests illustrate the distinction; the API documentation determines the behavior of real endpoints.

A practical checklist

  • Identify whether the operation retrieves data or sends data for processing.

  • Use GET for retrieval when the endpoint documentation supports it.

  • Use POST for submitted data when the endpoint documents that processing behavior.

  • Check the documented effects before repeating a POST.

  • Confirm each endpoint’s method, parameters, and behavior in its API documentation.

A few more useful answers

Can a GET request change data if an API allows it?

GET is defined for retrieval, not for requesting a change. Follow the endpoint documentation, but don’t treat an API-specific convention as GET’s general purpose. [S1]

Is it always safe to repeat a POST?

No. POST is not classified as safe or idempotent by default, and repeating an identical request may have additional effects. Check the specific endpoint’s documentation. [S2]

Does this guide determine how every API behaves?

No. It covers general HTTP method semantics. An API’s documentation determines the method, parameters, and behavior of its particular endpoints. [S1] [S2]

Sources

References used for this guide.

  1. [S1] GET request method — HTTP | MDN
    developer.mozilla.org · Checked
  2. [S2] POST request method — HTTP | MDN
    developer.mozilla.org · Checked

YOUR QUESTION. YOUR DETAILS.

Let’s work through your situation.

Get a tailored answer or help with your next task. Starts at $1, with a quote before you pay.

Ask your own question
← Back to Geez at Work