A REST API POST is an HTTP method used to send data to a server so it creates a new resource, such as a new user, order, or record. The key condition is that POST is not guaranteed to be safe or idempotent: sending the same POST twice can create two resources, so you need to design for that.
What POST Does in REST
REST (Representational State Transfer) is a style for building web services around resources, each identified by a URL. The HTTP method tells the server what to do with that resource. POST means "create a new subordinate resource under the target collection."
The target is usually a collection endpoint, such as /users or /orders. The request body carries the data for the new resource, typically as JSON. The server validates the body, assigns an identifier, stores the resource, and returns a response.
POST is one of several methods. GET reads a resource, PUT replaces a resource at a known URL, PATCH updates part of it, and DELETE removes it. POST is the one you reach for when the client does not yet know the new resource's URL, because the server creates it.
Anatomy of a POST Request
A POST request has four parts you should be able to point to:
- Method and URL:
POST /api/userstargets the users collection. - Headers: at minimum
Content-Type: application/jsonso the server knows how to parse the body. Authentication usually rides here too, such as a bearer token. - Body: the JSON payload with the fields for the new resource.
- Response: a status code plus, often, the created resource including its new ID.
A minimal example body for creating a user might be {"name": "Sam", "email": "sam@example.com"}. The server responds with 201 Created, a Location header pointing at /api/users/42, and a body containing the stored record with id: 42.
Status Codes You Will See
The response code tells you what happened, and each one implies a different next step:
- 201 Created: success, and a new resource exists. Read the
Locationheader or the returned ID. - 200 OK: success, but the server chose not to return 201. The body usually holds the result.
- 400 Bad Request: the JSON is malformed or a field is missing. Fix the body and retry.
- 401 Unauthorized / 403 Forbidden: your credentials are missing, expired, or lack permission. Do not retry blindly.
- 404 Not Found: the collection URL is wrong.
- 409 Conflict: the resource already exists, for example a duplicate email.
- 422 Unprocessable Entity: the JSON parsed but failed validation, such as an invalid date format.
- 500 Internal Server Error: the server failed. Retrying once may help; repeated retries usually will not.
POST vs PUT and PATCH
The clearest distinction is who decides the URL. With POST to /users, the server assigns the new ID and returns it. With PUT to /users/42, the client already knows the URL and sends the full representation to create or replace it. PATCH to the same URL sends only the fields that change.
A common misconception is that POST and PUT are interchangeable for creating records. They are not: PUT is idempotent, so repeating it produces the same end state, while repeating a POST can create duplicates. If your client retries a failed POST automatically, you can end up with two orders. Guard against that with an idempotency key in a header, which lets the server recognise a repeat and return the original result instead of creating again.
An Example
Suppose a shop's API exposes POST /api/orders. You send this body:
{
"customer_id": 17,
"items": [{"sku": "TEA-01", "quantity": 2}],
"note": "leave at door"
}
The server checks that customer 17 exists, that the SKU is valid, and that quantity is a positive integer. It then creates order 9031, calculates the total, and replies with 201 Created and Location: /api/orders/9031. If you send the identical body again without an idempotency key, you get order 9032 with the same contents. That is correct POST behaviour, and it is exactly why retries need care.
If the body instead had "quantity": 0, a well-built API returns 422 with a message naming the field. If the SKU did not exist, you might see 400 or 422 depending on the API's validation style. Read the error body: good APIs tell you which field failed and why.
Testing a POST Safely
- Start against a test or sandbox environment, never production, until the request works reliably.
- Set the method to POST, paste the collection URL, and add
Content-Type: application/json. - Add authentication exactly as the API documentation specifies, usually a header.
- Paste a small, valid JSON body and send. Read the status code before reading the body.
- On success, copy the returned ID and immediately GET the new resource's URL to confirm it was stored as intended.
- Deliberately send one invalid field to see how errors are shaped, so your client code can handle them.
Labels in API tools and dashboards differ by version, so match the concepts rather than exact menu names. Keep your test bodies in a file so you can repeat the same request after changes.
What Goes Wrong and How to Fix It
415 Unsupported Media Type usually means the Content-Type header is missing or wrong. Set it to application/json and make sure the body is valid JSON, with double quotes around keys and no trailing comma.
401 after a token refresh often means the old token is still cached. Clear it and send the new one. 409 on a create usually means a unique field, such as an email, already exists; check before creating or handle the conflict in your client.
Timeouts are the dangerous case, because you do not know whether the server created the resource. Retrying without an idempotency key risks a duplicate. Log the request, check by a unique field, and only then decide whether to resend.
Finally, never put sensitive data in the URL query string on a POST; keep it in the body and use HTTPS. Validate on the server regardless of what your client checks, because clients can be bypassed.
Does POST always create something new?
In REST practice, yes: POST to a collection creates a subordinate resource. Some APIs also use POST for actions that are not simple creates, such as submitting a search or triggering a process, so read the endpoint's documentation.
Can a POST request have no body?
It can, but then it usually triggers an action rather than creating a record with fields. If you are creating a resource, send the fields in the body.
Why does the same POST create duplicates?
Because POST is not idempotent by design. Each accepted request is a new creation. Use an idempotency key or a uniqueness check when retries are possible.