Bird
0
0

Given this Python code using the requests library, what will be the HTTP status code if the resource is created successfully?

medium📝 Predict Output Q13 of 15
Rest API - HTTP Methods
Given this Python code using the requests library, what will be the HTTP status code if the resource is created successfully?
import requests
url = 'https://api.example.com/items'
data = {'name': 'Book', 'price': 12.99}
response = requests.post(url, json=data)
print(response.status_code)
A200
B404
C201
D500
Step-by-Step Solution
Solution:
  1. Step 1: Understand POST success codes

    When a resource is created, the server usually returns HTTP status 201 Created.
  2. Step 2: Analyze the code behavior

    The code sends a POST request with JSON data; if successful, response.status_code will be 201.
  3. Final Answer:

    201 -> Option C
  4. Quick Check:

    POST success = 201 Created [OK]
Quick Trick: 201 means resource created successfully [OK]
Common Mistakes:
  • Confusing 200 OK with 201 Created
  • Assuming 404 means success
  • Thinking 500 means success

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes