Writing sample requests and responses well is crucial for making your API documentation developer-friendly and easy to adopt. Here are
best practices to follow when creating them:
1. Use Realistic and Complete Examples
Show actual field values, not placeholders like string,
123, or true.
Include all required fields, and optionally include extras to show flexibility.
Bad:
{
"name": "string",
"age": 123
}
Good:
{
"name": "Alice Johnson",
"age": 29
}
2. Include Full HTTP Requests and Responses
Show the full request: method, URL, headers, body.
Likewise, show the full response: status code, headers, body.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Writing sample requests and responses well is crucial for making your API documentation developer-friendly and easy to adopt. Here are best practices to follow when creating them:
1. Use Realistic and Complete Examples
string,123, ortrue.Bad:
Good:
2. Include Full HTTP Requests and Responses
Example:
3. Provide Multiple Examples
4. Language-Specific Code Snippets
Example in curl:
5. Label and Format Clearly
json,http,bash)6. Explain the Example
Example:
7. Avoid Redundancy, But Show Variety
8. Show Pagination and Filtering
?page=2&limit=10nextURLs in the response.9. Keep Examples in Sync with the API
10. Keep Responses Simple and Focused
...or// other fieldsif necessary.Bonus: Sample Template
Response:
201 CreatedResponse:
400 Bad Request