0
0
Rest APIprogramming~20 mins

200 OK and 201 Created in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
REST API Status Code Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
1:00remaining
What is the HTTP status code returned for a successful GET request?

Consider a REST API where a client sends a GET request to retrieve data. Which HTTP status code should the server return to indicate success?

A200 OK
B201 Created
C404 Not Found
D500 Internal Server Error
Attempts:
2 left
💡 Hint

Think about the difference between retrieving existing data and creating new data.

Predict Output
intermediate
1:00remaining
What status code is returned after successfully creating a new resource?

When a client sends a POST request to create a new resource, which HTTP status code should the server return to indicate the resource was created successfully?

A204 No Content
B200 OK
C201 Created
D400 Bad Request
Attempts:
2 left
💡 Hint

This status code means something new was made.

🧠 Conceptual
advanced
1:30remaining
Why should a POST request return 201 Created instead of 200 OK?

Explain why it is better REST practice for a POST request that creates a resource to return 201 Created rather than 200 OK.

A201 Created explicitly indicates a new resource was created, while 200 OK only means the request succeeded without specifying creation.
B201 Created is used only when the resource is created on the client side, not the server side.
C201 Created means the server will send the resource again in the response body, 200 OK does not.
D200 OK is only for GET requests and cannot be used for POST requests.
Attempts:
2 left
💡 Hint

Think about the meaning of each status code and what information it conveys to the client.

Predict Output
advanced
1:30remaining
What is the response status code and body after a successful POST creating a resource with location header?

A client sends a POST request to create a new user. The server creates the user and returns a response with a Location header pointing to the new user URL. What is the expected status code and typical response body?

AStatus: 404 Not Found, Body: Error message
BStatus: 200 OK, Body: Empty
CStatus: 204 No Content, Body: Empty
DStatus: 201 Created, Body: JSON with new user details
Attempts:
2 left
💡 Hint

Think about what 201 Created means and what the Location header is for.

🧠 Conceptual
expert
2:00remaining
How should a REST API handle a POST request that creates a resource but the client sends duplicate data?

A client sends a POST request to create a resource, but the resource already exists with the same data. What is the best RESTful status code and response behavior?

AReturn 404 Not Found because the resource cannot be created again.
BReturn 409 Conflict with an error message explaining the duplicate resource.
CReturn 200 OK with no body to silently ignore the duplicate.
DReturn 201 Created again with the existing resource data.
Attempts:
2 left
💡 Hint

Think about how to inform the client that the resource already exists and cannot be duplicated.