Bird
Raised Fist0
Rest APIprogramming~20 mins

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

Choose your learning style10 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.

Practice

(1/5)
1. What does the HTTP status code 200 OK indicate in a REST API response?
easy
A. A new resource was successfully created on the server.
B. The request was successful and the server is returning the requested data or confirmation.
C. The client made a bad request and the server could not understand it.
D. The server encountered an error and could not complete the request.

Solution

  1. Step 1: Understand the meaning of 200 OK

    The status code 200 OK means the request was successful and the server is sending back the requested data or confirmation.
  2. Step 2: Compare with other codes

    201 Created means a new resource was created, which is different from 200 OK.
  3. Final Answer:

    The request was successful and the server is returning the requested data or confirmation. -> Option B
  4. Quick Check:

    200 OK = Success with data [OK]
Hint: 200 OK means success with data returned [OK]
Common Mistakes:
  • Confusing 200 OK with 201 Created
  • Thinking 200 means resource creation
  • Mixing 200 with client or server error codes
2. Which of the following is the correct way to indicate a successful creation of a new resource in a REST API response?
easy
A. HTTP/1.1 201 Created
B. HTTP/1.1 404 Not Found
C. HTTP/1.1 500 Internal Server Error
D. HTTP/1.1 200 OK

Solution

  1. Step 1: Identify the status code for resource creation

    The status code 201 Created is used when a new resource is successfully created on the server.
  2. Step 2: Eliminate incorrect options

    200 OK means success but not necessarily creation; 404 and 500 are error codes.
  3. Final Answer:

    HTTP/1.1 201 Created -> Option A
  4. Quick Check:

    201 Created = New resource created [OK]
Hint: Use 201 Created for new resource success [OK]
Common Mistakes:
  • Using 200 OK instead of 201 for creation
  • Confusing 404 Not Found as success
  • Mixing error codes with success codes
3. Consider this REST API response code snippet:
HTTP/1.1 201 Created
Location: /users/123

{"id":123,"name":"Alice"}

What does this response tell the client?
medium
A. The client made a bad request and should try again.
B. The request failed and no resource was created.
C. The server is returning existing user data without creating anything new.
D. A new user resource was created with ID 123, and its location is provided.

Solution

  1. Step 1: Analyze the status code 201 Created

    This code means a new resource was successfully created on the server.
  2. Step 2: Interpret the Location header and response body

    The Location header shows where the new resource is located (/users/123), and the body contains the new user's data.
  3. Final Answer:

    A new user resource was created with ID 123, and its location is provided. -> Option D
  4. Quick Check:

    201 Created + Location header = New resource created [OK]
Hint: 201 with Location means new resource created [OK]
Common Mistakes:
  • Ignoring the Location header
  • Thinking 201 means failure
  • Confusing 201 with 200 OK
4. You wrote a REST API endpoint to create a new product. The server returns 200 OK instead of 201 Created. What is the likely issue?
medium
A. The server did not create a new resource but only confirmed the request.
B. The client sent an invalid request format.
C. The server successfully created the resource but forgot to set the correct status code.
D. The server encountered an internal error while creating the resource.

Solution

  1. Step 1: Understand the difference between 200 OK and 201 Created

    200 OK means success but not necessarily resource creation; 201 Created explicitly means a new resource was created.
  2. Step 2: Analyze the server behavior

    If the resource was created but 200 OK was returned, the server likely forgot to set the correct status code.
  3. Final Answer:

    The server successfully created the resource but forgot to set the correct status code. -> Option C
  4. Quick Check:

    201 Created must be set on resource creation [OK]
Hint: 201 must be set when resource is created [OK]
Common Mistakes:
  • Assuming 200 OK means creation
  • Ignoring status code importance
  • Confusing client errors with server response codes
5. You are designing a REST API for a blog. When a new post is created, you want to return the correct status code and the URL of the new post. Which response is the best practice?
hard
A. Return 201 Created with the Location header set to the new post URL and the post data in the body.
B. Return 404 Not Found because the post did not exist before.
C. Return 200 OK with the post data in the body but no Location header.
D. Return 500 Internal Server Error to indicate the server created the post.

Solution

  1. Step 1: Identify the correct status code for resource creation

    201 Created is the standard code to indicate a new resource was successfully created.
  2. Step 2: Use the Location header to provide the new resource URL

    Including the Location header with the new post URL helps clients find the resource easily.
  3. Final Answer:

    Return 201 Created with the Location header set to the new post URL and the post data in the body. -> Option A
  4. Quick Check:

    201 Created + Location header = Best practice for new resource [OK]
Hint: Use 201 Created + Location header for new resources [OK]
Common Mistakes:
  • Returning 200 OK without Location header
  • Using error codes for successful creation
  • Not including the new resource URL
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard