Endpoint documentation helps people understand how to use a web service. It explains what each URL does and how to talk to it.
When you build a web service that others will use.
When you want to explain how to send data to your API.
When you want to show what data your API sends back.
When you want to help developers avoid mistakes using your API.
When you want to keep your API easy to maintain and update.
Syntax
Rest API
Endpoint: /resource
Method: GET | POST | PUT | DELETE
Description: What this endpoint does
Request Parameters:
- name (type): description
Request Body:
{
"field": "type"
}
Response:
Status Code: description
Body:
{
"field": "type"
}
Use clear names for endpoints and methods.
Include examples of requests and responses if possible.
Examples
This example shows how to get users with a page number.
Rest API
Endpoint: /users
Method: GET
Description: Get a list of users
Request Parameters:
- page (int): page number
Response:
Status Code: 200 OK
Body:
[
{"id": 1, "name": "Alice"},
{"id": 2, "name": "Bob"}
]
This example shows how to add a new user by sending their name and email.
Rest API
Endpoint: /users
Method: POST
Description: Create a new user
Request Body:
{
"name": "string",
"email": "string"
}
Response:
Status Code: 201 Created
Body:
{
"id": 3,
"name": "string",
"email": "string"
}
Sample Program
This shows how to document an endpoint that returns books. It explains the URL, method, parameters, and response.
Rest API
/* Example of endpoint documentation for a simple API */
Endpoint: /books
Method: GET
Description: Retrieve a list of books
Request Parameters:
- author (string, optional): filter books by author name
Response:
Status Code: 200 OK
Body:
[
{"id": 101, "title": "Learn REST", "author": "Jane"},
{"id": 102, "title": "API Basics", "author": "John"}
]
OutputSuccess
Important Notes
Always keep your documentation up to date with your API changes.
Use simple language so everyone can understand.
Include error codes and messages to help users fix problems.
Summary
Endpoint documentation explains how to use each API URL.
It includes method, parameters, request and response details.
Good documentation makes APIs easier and safer to use.
Practice
(1/5)
1. What is the main purpose of endpoint documentation in a REST API?
easy
A. To explain how to use each API URL including methods and parameters
B. To store user data securely
C. To improve the speed of the API server
D. To design the user interface of a website
Solution
Step 1: Understand the role of endpoint documentation
Endpoint documentation describes how to use each API URL, including methods and parameters.
Step 2: Compare options with this role
Only To explain how to use each API URL including methods and parameters matches this purpose; others describe unrelated tasks.
Final Answer:
To explain how to use each API URL including methods and parameters -> Option A
Quick Check:
Endpoint documentation = Usage guide [OK]
Hint: Think: What helps users understand API URLs? [OK]
Common Mistakes:
Confusing documentation with data storage
Mixing API documentation with UI design
Assuming documentation improves server speed
2. Which of the following is the correct way to document the HTTP method in an endpoint documentation?
easy
A. "method": "GET"
B. "method" = GET
C. method: GET;
D. GET
Solution
Step 1: Identify proper JSON syntax for documentation
Endpoint docs often use JSON or similar formats; key-value pairs use colon and quotes for strings.
Step 2: Check each option's syntax
"method": "GET" uses correct JSON syntax with quotes and colon; others use invalid or non-standard syntax.
Final Answer:
"method": "GET" -> Option A
Quick Check:
JSON key-value = colon + quotes [OK]
Hint: Remember JSON syntax: key in quotes, colon, value in quotes [OK]
But the API returns a 400 error when you send the request. What is the most likely mistake in the documentation?
medium
A. The endpoint URL is missing a trailing slash
B. The HTTP method should be GET, not POST
C. Parameters should be inside a "requestBody" section, not "parameters"
D. The response code 201 is incorrect for creation
Solution
Step 1: Understand POST request structure
POST requests usually send data in the request body, not as URL parameters.
Step 2: Check documentation structure
Parameters listed under "parameters" implies URL/query parameters; for POST data, it should be under "requestBody".
Final Answer:
Parameters should be inside a "requestBody" section, not "parameters" -> Option C
Quick Check:
POST data = requestBody, not parameters [OK]
Hint: POST data goes in requestBody, not parameters [OK]
Common Mistakes:
Confusing query parameters with request body
Changing HTTP method incorrectly
Ignoring correct response codes
5. You want to document an endpoint that updates a user's email. It uses PATCH method at /users/{id}. The request body must include email as a string. The response returns 200 with updated user data or 400 if email is invalid. Which is the best way to structure this documentation snippet?