The journal
Should PUT Return 200, 201, or 204? Test the Starting State
Test one URI when it is new and when it already exists, then check how the client handles a successful response with no body.

At a glance
Start from a known resource state. Expect 201 after creation and 200 or 204 after a completed update. Branch before parsing a 204.
In this guide
For a PUT that successfully creates a representation at a URI with none, HTTP specifies 201 Created. A successful PUT that modifies the existing representation uses 200 OK or 204 No Content. Test the starting state and what the client receives. The method name alone cannot tell a client to expect JSON or decide whether a resource was newly created.
Start with one known resource URI
Use an example URI such as /notes/window. The first fixture begins with no note at that URI. Send a complete representation for the resource. When the origin creates it successfully, expect 201. In the local fixture, the response includes the example URI and a JSON description. For a real 201, use the documented response format, and read any Location header as the resource identifier. RFC 9110 identifies the request target as the fallback when Location is absent.

Read the origin-server requirements in RFC 9110: PUT semantics.
Sources: RFC 9110: PUT semantics · RFC 9110: 201 Created
Compare updates with and without response content
Seed the resource before the second test. Send a replacement with the same target URI. An API can return 200 with a representation when that helps the client confirm the saved state. It can return 204 when it has applied the change and has no content to send back. A 204 can still carry response headers.
If you choose the 204 design, make the client branch before attempting to parse the body. In the local Fetch Response fixture, an unconditional JSON parse on a 204 threw a parse error, even though the saved state was correct. Store that test separately from a failing write.

Two successful update contracts
200 OK with a representation
The example returns the saved note in a documented JSON body.
204 No Content
The example confirms the write and returns an empty body. The client skips parsing.
Check header and body expectations in RFC 9110: 204 No Content.
Sources: RFC 9110: PUT semantics · RFC 9110: 204 No Content
Repeat the same write and check the final record
In an illustrative memory-only fixture, the first write produced 201, the second returned a new representation with 200, and an identical repeat finished with 204. The final in-memory resource stayed the same after the repeat. The example chooses to include a representation on one update and omit it on another to test both allowed kinds of response.
Idempotence is about the intended effect of repeated requests. A repeated PUT can preserve the same final state while returning a different status than the first, since creation and later updates start from different states. Match both tests to the API's published contract.
| Starting state | Fixture response | Assertion |
|---|---|---|
| No representation | 201 Created | One note and the expected resource URI |
| Existing note | 200 OK | The updated representation has the new label |
| The same label already saved | 204 No Content | No body. Final label remains unchanged. |


Verify the definition in RFC 9110: idempotent methods.
Sources: RFC 9110: PUT semantics · RFC 9110: idempotent methods · RFC 9110: 204 No Content
If you are comparing PUT with other methods on the same service, trace GET, POST, PUT and DELETE on one example record and check the method and target before the status.
Keep the assertions tied to the actual contract
Verify the state before and after the write, whether the response includes the representation, and what the client does without a body. This breakdown assumes that the API permits creation at the client-selected URI. If the API only updates existing resources, test its documented missing-resource behavior separately. If the work is merely accepted for later processing, it calls for a different contract from a completed write.
Check the successful write contract
- Control whether the target begins empty.
- Assert code and headers together.
- Check whether the response includes content.
- Read the final resource or stored fixture state.
For the related task, see Separate accepted work from a completed write.
Sources: RFC 9110: PUT semantics · RFC 9110: 201 Created · RFC 9110: 204 No Content
Frequently asked questions
Can the second identical PUT return a different status?
Yes. If the first request creates the resource, the second starts with an existing resource. The intended final state can be the same.
Must a PUT modify an existing resource?
An API can permit creating a representation at the target URI. Check the API contract before sending a write.
Is 202 the same as an update that returned no body?
202 describes accepted work whose processing is incomplete. 204 confirms a successful completed action with no response content.
What if a 201 has no Location header?
RFC 9110 uses the request target as the fallback identifier for the principal created resource.
Check the broader 201 response rules
Confirm the resource identifier and when to use it.
Review the resource creation responseContinue with a related guide
- Check the broader 201 response rules
Confirm the resource identifier and when to use it.
- Separate accepted work from a completed write
Use a different test for work still in progress.
- Review the meaning of idempotence
Compare the intended final resource state after a repeated request.