Bird
0
0

Given this POST request code snippet, what will be the server's response status if the resource is created successfully?

medium📝 Predict Output Q4 of 15
Rest API - HTTP Methods
Given this POST request code snippet, what will be the server's response status if the resource is created successfully?
fetch('https://api.example.com/items', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ name: 'Book', price: 10 })
})
.then(response => response.status)
A201
B404
C400
D200
Step-by-Step Solution
Solution:
  1. Step 1: Understand fetch POST request behavior

    When a resource is created, server returns 201 Created status.
  2. Step 2: Match response.status with creation success

    201 is the standard success code for resource creation.
  3. Final Answer:

    201 -> Option A
  4. Quick Check:

    POST success status = 201 [OK]
Quick Trick: Successful POST returns 201 status code [OK]
Common Mistakes:
  • Assuming 200 means creation success
  • Confusing 400 client error with success
  • Ignoring 201 as the creation confirmation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes