This adds a new blog post with a title and content.
Rest API
POST /posts HTTP/1.1
Host: example.com
Content-Type: application/json
{
"title": "My First Post",
"content": "Hello world!"
}
Sample Program
This Python program sends a POST request to create a new post with title, body, and userId. It prints the status code and the response from the server.
Using data=data sends form-encoded data, but API expects JSON for POST creation.
Step 2: Fix data format
Use json=data in requests.post to send JSON body, which the server accepts.
Final Answer:
The data should be sent as JSON, not form data -> Option A
Quick Check:
Send JSON with json= parameter [OK]
Hint: Use json= not data= to send JSON body [OK]
Common Mistakes:
Sending form data instead of JSON
Assuming URL is wrong without checking
Thinking POST can't send data
Ignoring HTTPS requirement
5. You want to create a new blog post resource with title and content using a POST request. Which of these JSON payloads correctly represents the data to send in the request body?
hard
A. ["title", "My Day", "content", "It was sunny."]
B. "title=My Day&content=It was sunny."
C. {"My Day": "title", "It was sunny.": "content"}
D. {"title": "My Day", "content": "It was sunny."}
Solution
Step 1: Understand JSON object structure
JSON objects use key-value pairs with keys as strings and values as data.
Step 2: Identify correct JSON format
{"title": "My Day", "content": "It was sunny."} correctly uses keys "title" and "content" with their string values in an object.
Final Answer:
{"title": "My Day", "content": "It was sunny."} -> Option D
Quick Check:
JSON object with keys and values = {"title": "My Day", "content": "It was sunny."} [OK]
Hint: JSON data must be key-value pairs inside braces {} [OK]
Common Mistakes:
Using JSON arrays instead of objects
Swapping keys and values
Sending URL-encoded string instead of JSON
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.