← Blog
API Fundamentals

PUT vs PATCH vs POST: Which HTTP Method Should Your API Use?

PUT vs PATCH vs POST: Which HTTP Method Should Your API Use?

The difference between POST, PUT, and PATCH comes down to three things: intent, idempotency, and scope. POST creates a new resource and lets the server assign its identifier. PUT replaces an existing resource in full at a known URL. PATCH applies a partial update to a resource, changing only the fields you send. In Apidoke's API Blueprint editor, documenting each method correctly signals these semantics to every developer reading your published reference.

  • POST is for creation; the server picks the new resource's URL and returns it in a Location header with a 201 Created status.
  • PUT is idempotent: calling it ten times with the same body produces the same result as calling it once. Omitted fields are cleared or set to defaults.
  • PATCH is not guaranteed to be idempotent and only touches the fields you include in the request body.
  • Choosing the wrong method is a contract violation your consumers will feel as bugs, not design decisions.

Why HTTP method semantics matter more than people think

HTTP methods are part of a formal contract defined in RFC 9110 (HTTP Semantics). When a client caches a response, retries a failed request, or follows a redirect, it relies on the method's defined properties. Use the wrong one and you get accidental duplicates on retry, caches that serve stale data, or clients that refuse to retry at all because they cannot know whether the operation is safe to repeat.

Idempotency (a word worth defining once and using precisely) means that repeating the same request any number of times produces the same server state as doing it once. GET, PUT, and DELETE are idempotent. POST and PATCH are not required to be, though PATCH can be designed that way in practice.

POST: creating resources when the server owns the ID

Use POST when you want the server to mint a new identifier for a resource. The canonical example is adding an item to a collection.

POST /orders HTTP/1.1
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9...

{
  "product_id": "prod_8821",
  "quantity": 2
}

The server responds with 201 Created and a Location header pointing to the new resource:

HTTP/1.1 201 Created
Content-Type: application/json
Location: /orders/ord_4491

{
  "id": "ord_4491",
  "product_id": "prod_8821",
  "quantity": 2,
  "status": "pending"
}

POST is not idempotent. If a network timeout causes the client to retry, the server may create two orders. That is why idempotency keys exist: a client-generated Idempotency-Key header lets the server detect and deduplicate retried POSTs, but that is an application-layer convention layered on top of the HTTP method, not a property of POST itself.

Other legitimate uses of POST include submitting a form, triggering an action that does not map cleanly to a resource (like POST /invoices/inv_99/send), or any operation whose output is not a simple stored object.

PUT: replacing a resource in full

Use PUT when the client knows the full URL of the resource it wants to create or replace. The body must contain the complete intended state. Fields absent from the request are treated as absent from the resource, not left unchanged.

PUT /orders/ord_4491 HTTP/1.1
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9...

{
  "product_id": "prod_8821",
  "quantity": 5,
  "status": "pending"
}

Response on success:

HTTP/1.1 200 OK
Content-Type: application/json

{
  "id": "ord_4491",
  "product_id": "prod_8821",
  "quantity": 5,
  "status": "pending"
}

If the resource did not exist and the server allows client-defined IDs, PUT may respond with 201 Created instead. If it did exist, 200 OK or 204 No Content are both correct. The key point is that sending the same PUT request repeatedly is safe; the tenth call leaves the server in exactly the same state as the first.

The practical risk with PUT is accidental data loss. A client that reads a resource, updates one field in memory, and PUTs the whole object back is safe. A client that constructs the PUT body without first reading the resource risks wiping out fields it did not know existed, like a metadata object added by another system.

PATCH: partial updates

PATCH sends only the fields you want to change. The server merges your payload into the existing resource rather than replacing it wholesale.

PATCH /orders/ord_4491 HTTP/1.1
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9...

{
  "quantity": 3
}
HTTP/1.1 200 OK
Content-Type: application/json

{
  "id": "ord_4491",
  "product_id": "prod_8821",
  "quantity": 3,
  "status": "pending"
}

Only quantity changed. product_id and status were untouched because they were absent from the request body. That is the whole point.

PATCH is not required to be idempotent by spec, though many implementations are. Consider an endpoint that appends to a list each time it is called: two identical PATCHes produce a different result than one. If you want safety on retry, document the behaviour explicitly and consider supporting an idempotency key.

PATCH also has a formal patch format, JSON Patch (RFC 6902), which uses an array of operations like add, remove, and replace against a JSON Pointer path. Most REST APIs skip the formal format and just accept a plain JSON object of changed fields with Content-Type: application/json. Both approaches are valid; what matters is documenting which one you use.

Comparing POST, PUT, and PATCH side by side

PropertyPOSTPUTPATCH
Primary intentCreate a new resourceReplace a resource in fullPartially update a resource
Client provides URL?No (server assigns it)YesYes
Idempotent?NoYesNot required (depends on design)
Body scopeNew resource fieldsFull resource stateChanged fields only
Typical success code201 Created200 OK or 204 No Content200 OK or 204 No Content
Returns Location header?Yes (new resource URL)RarelyRarely
Risk on network retryDuplicate creationHarmless (same state)Depends on implementation

Common mistakes and how to spot them in your API

Using POST for every write operation

Some teams default to POST for all mutations because it feels simpler. The cost: clients cannot safely retry on timeout, reverse proxies cannot cache, and developers reading the docs have to guess whether a call is idempotent. If the operation is a full replacement, use PUT. If it is a targeted field update, use PATCH.

Using PUT when you mean PATCH

This is the quiet data-loss bug. A mobile client on a slow connection reads a user profile, the user changes only their email, and the app PUTs back a payload it built from local state. If another device or background process updated a field in the gap, that change is gone. PATCH is the right tool here.

Expecting PATCH to be safe on retry without an idempotency key

If your PATCH appends to a list, increments a counter, or triggers a side effect, sending it twice creates inconsistency. Document this clearly, and if retry safety matters, require clients to send an Idempotency-Key header and explain what your server does with it.

Returning 200 OK with no body after PUT

Returning 204 No Content is fine and slightly more efficient. Returning 200 OK without a body is technically a protocol violation because 200 promises content. Pick one and document it consistently. See our guide on choosing the right error status codes for related status code decisions.

How to document POST, PUT, and PATCH in API Blueprint

API Blueprint (the Markdown-based format Apidoke uses) makes the HTTP method part of each action heading. Here is a minimal but complete example covering all three methods on an orders resource:

FORMAT: 1A
HOST: https://api.example.com

# Orders API

## Orders Collection [/orders]

### Create an Order [POST]

Creates a new order. The server assigns the order ID and returns it
in the `Location` response header.

+ Request (application/json)

        {
          "product_id": "prod_8821",
          "quantity": 2
        }

+ Response 201 (application/json)

    + Headers

            Location: /orders/ord_4491

    + Body

            {
              "id": "ord_4491",
              "product_id": "prod_8821",
              "quantity": 2,
              "status": "pending"
            }

## Order [/orders/{id}]

+ Parameters
    + id (string, required) - The order ID.

### Replace an Order [PUT]

Replaces the entire order. All fields must be included;
omitted fields revert to their defaults.

+ Request (application/json)

        {
          "product_id": "prod_8821",
          "quantity": 5,
          "status": "pending"
        }

+ Response 200 (application/json)

        {
          "id": "ord_4491",
          "product_id": "prod_8821",
          "quantity": 5,
          "status": "pending"
        }

### Update an Order [PATCH]

Partially updates the order. Send only the fields you want to change.

+ Request (application/json)

        {
          "quantity": 3
        }

+ Response 200 (application/json)

        {
          "id": "ord_4491",
          "product_id": "prod_8821",
          "quantity": 3,
          "status": "pending"
        }

Paste that into Apidoke's split-pane editor and the live preview instantly renders three separate action panels, one per method. Developers can open the try-it console and fire each request against your real API without leaving the browser. Auth tokens they enter stay in the browser and never pass through Apidoke's servers, which matters when testing against a production endpoint. For the full syntax reference, the API Blueprint syntax cheat-sheet covers every keyword with copy-paste examples.

Three-column Apidoke doc viewer showing POST, PUT, and PATCH actions for an Orders resource, with the try-it console panel open on PATCH

When to use each method in practice: a decision guide

  1. Is the client creating something new and the server should mint the ID? Use POST to a collection URL like /orders. Expect 201 Created and a Location header back.
  2. Is the client sending the complete intended state of a resource at a known URL? Use PUT to /orders/{id}. Warn consumers in your docs that omitted fields will be reset.
  3. Is the client changing one or a handful of fields without touching the rest? Use PATCH to /orders/{id}. Document exactly which fields are patchable and what a missing field means (unchanged, not deleted).
  4. Is the client triggering an action rather than storing a resource? POST is usually correct. For example, POST /invoices/{id}/void does not update a field; it transitions state. Document the resulting resource state and the response code (200 with the updated invoice body, or 204 if the action needs no return value).
  5. Does retry safety matter? Prefer PUT over POST. If you must use POST or PATCH, document idempotency key support or state explicitly that retries may duplicate side effects.

What about DELETE and GET?

GET retrieves a resource without side effects, DELETE removes it. Both are idempotent (a second DELETE on an already-deleted resource returns 404 Not Found or 204 No Content depending on how strictly you follow spec; either is fine as long as it is consistent). They are part of the same HTTP semantics family, but they are rarely confused with POST, PUT, or PATCH, so this article keeps its focus on the create-and-update triad.

Documenting error cases for each method

Method choice affects which errors are possible. A few worth documenting explicitly:

  • POST to a collection where uniqueness is enforced: 409 Conflict when a duplicate key is detected.
  • PUT or PATCH to a non-existent resource when the server does not allow creation via PUT: 404 Not Found.
  • PUT or PATCH with a body that fails validation: 422 Unprocessable Content (not 400 Bad Request, which signals a malformed request, not a semantically invalid one).
  • Any method without valid credentials: 401 Unauthorized. With credentials that lack permission: 403 Forbidden.

Spelling these out in your Blueprint response blocks means the try-it console in Apidoke shows consumers exactly what to expect, and the published reference becomes the single source of truth rather than tribal knowledge in a Slack channel.

Frequently asked questions

What is the main difference between POST and PUT?

POST creates a new resource and lets the server choose its URL, returning 201 Created with a Location header. PUT replaces an existing resource in full at a URL the client already knows, returning 200 OK or 204 No Content. PUT is idempotent; POST is not.

Can I use PUT to create a resource?

Yes, if the client knows or generates the resource's identifier upfront. A PUT to /users/usr_7723 that does not yet exist may return 201 Created if your server supports it. Document this behaviour explicitly so consumers know whether to expect 200 or 201.

Is PATCH always safer than PUT for updates?

PATCH avoids accidental data loss because you send only the fields you intend to change. But PATCH is not guaranteed to be idempotent, so it carries retry risk. PUT is idempotent but requires the client to send the entire resource state. The right choice depends on whether full-replacement semantics or partial-update safety matter more for your use case.

What HTTP status code should POST return?

201 Created is correct when a new resource was created, paired with a Location header containing the new resource's URL. If POST triggers an action without creating a named resource, 200 OK with a response body, or 204 No Content without one, are both acceptable.

How do I document POST vs PUT vs PATCH in API Blueprint?

Use a separate action heading for each method under the same resource, for example ### Create an Order [POST] and ### Replace an Order [PUT]. Include distinct request bodies and response blocks for each. Apidoke renders them as individual panels with independent try-it consoles, so developers can test all three without leaving the docs page.

Ready to publish these method distinctions as clean, interactive API docs? Open Apidoke at docs.apidoke.com/login, paste your API Blueprint, and share a live reference your team can read and test in minutes, no toolchain required.