0
0
Rest APIprogramming~20 mins

POST for creating resources in Rest API - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
REST POST Mastery
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 after a successful POST request?

Consider a REST API where you send a POST request to create a new user. The server successfully creates the user and returns a response.

What is the typical HTTP status code you expect in the response?

A200 OK
B404 Not Found
C500 Internal Server Error
D201 Created
Attempts:
2 left
💡 Hint

Think about the status code that indicates a new resource was successfully created.

Predict Output
intermediate
1:30remaining
What is the response body after creating a resource with POST?

You send a POST request to create a new book resource. The server responds with JSON containing the new book's ID and title.

What is the expected JSON response body?

Rest API
POST /books HTTP/1.1
Host: example.com
Content-Type: application/json

{"title": "Learn REST"}
A{"id": 101, "title": "Learn REST"}
B{"error": "Missing title"}
C{"status": "success"}
D{}
Attempts:
2 left
💡 Hint

The server usually returns the created resource with its new ID.

🔧 Debug
advanced
2:00remaining
Why does this POST request return 400 Bad Request?

Examine the following POST request code snippet. It tries to create a new user but the server returns a 400 Bad Request error.

POST /users HTTP/1.1
Host: api.example.com
Content-Type: application/json

{"username": "", "email": "user@example.com"}

What is the most likely cause of the 400 error?

AThe email field is missing
BThe Content-Type header is missing
CThe username field is empty, violating validation rules
DThe HTTP method should be GET instead of POST
Attempts:
2 left
💡 Hint

Check the data sent in the request body for required fields.

🧠 Conceptual
advanced
1:00remaining
Which header is important to include in a POST request with JSON data?

When sending a POST request with JSON data to create a resource, which HTTP header must you include to inform the server about the data format?

AContent-Type
BAuthorization
CAccept-Encoding
DCache-Control
Attempts:
2 left
💡 Hint

This header tells the server what format the request body is in.

Predict Output
expert
1:30remaining
What is the value of the Location header after a successful POST?

A POST request creates a new resource at the server. The server responds with status 201 Created and includes a Location header.

What does the Location header contain?

AThe URL of the POST endpoint
BThe URL of the newly created resource
CThe client's IP address
DThe server's root URL
Attempts:
2 left
💡 Hint

The Location header tells the client where to find the new resource.