Skip to content

Commit d3fd8e9

Browse files
Add new file: docs/API Reference Guide.md
1 parent d3b15c9 commit d3fd8e9

File tree

1 file changed

+219
-0
lines changed

1 file changed

+219
-0
lines changed

docs/API Reference Guide.md

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
2+
# API Reference Guide
3+
4+
## Introduction
5+
6+
This document provides a comprehensive reference for the API, detailing all available endpoints, request and response formats, parameters, and status codes. It is intended for developers and technical architects who are integrating with our API.
7+
8+
## Endpoints Overview
9+
10+
This section provides a high-level overview of the available API endpoints.
11+
12+
| Endpoint | Method | Description |
13+
|---|---|---|
14+
| `/example` | `GET` | Retrieves a list of example resources. |
15+
| `/example/{id}` | `GET` | Retrieves a specific example resource by ID. |
16+
| `/example` | `POST` | Creates a new example resource. |
17+
| `/example/{id}` | `PUT` | Updates an existing example resource by ID. |
18+
| `/example/{id}` | `DELETE` | Deletes an example resource by ID. |
19+
20+
## Request/Response Format
21+
22+
All API requests and responses use JSON (JavaScript Object Notation) as the data format. The `Content-Type` header for requests should be set to `application/json`.
23+
24+
**Example Request Header:**
25+
26+
```
27+
Content-Type: application/json
28+
```
29+
30+
**Example Response Header:**
31+
32+
```
33+
Content-Type: application/json
34+
```
35+
36+
## Parameters
37+
38+
This section describes the different types of parameters used in the API.
39+
40+
* **Path Parameters:** These parameters are part of the URL path and are used to identify a specific resource. They are denoted by curly braces `{}` in the endpoint definition. For example, in `/example/{id}`, `id` is a path parameter.
41+
42+
* **Query Parameters:** These parameters are appended to the URL after a question mark `?` and are used to filter, sort, or paginate results. They are specified as key-value pairs, separated by ampersands `&`. For example, `/example?limit=10&offset=0`.
43+
44+
* **Request Body Parameters:** These parameters are included in the body of `POST`, `PUT`, and `PATCH` requests and are used to create or update resources. The format of the request body is JSON.
45+
46+
**Example: Query Parameters**
47+
48+
To retrieve the first 10 examples, sorted by name, you would use the following URL:
49+
50+
```
51+
/example?limit=10&offset=0&sort=name
52+
```
53+
54+
## Status Codes
55+
56+
The API uses standard HTTP status codes to indicate the success or failure of a request. Here's a summary of the most common status codes:
57+
58+
* **200 OK:** The request was successful.
59+
* **201 Created:** A new resource was successfully created.
60+
* **204 No Content:** The request was successful, but there is no content to return.
61+
* **400 Bad Request:** The request was invalid or malformed. The response body will typically contain more details about the error.
62+
* **401 Unauthorized:** The request requires authentication.
63+
* **403 Forbidden:** The user does not have permission to access the resource.
64+
* **404 Not Found:** The requested resource was not found.
65+
* **500 Internal Server Error:** An unexpected error occurred on the server.
66+
67+
## Example Endpoints
68+
69+
### GET /example
70+
71+
Retrieves a list of example resources.
72+
73+
**Request:**
74+
75+
```bash
76+
curl -X GET https://api.example.com/example
77+
```
78+
79+
**Response (200 OK):**
80+
81+
```json
82+
[
83+
{
84+
"id": 1,
85+
"name": "Example 1",
86+
"description": "This is the first example."
87+
},
88+
{
89+
"id": 2,
90+
"name": "Example 2",
91+
"description": "This is the second example."
92+
}
93+
]
94+
```
95+
96+
### GET /example/{id}
97+
98+
Retrieves a specific example resource by ID.
99+
100+
**Request:**
101+
102+
```bash
103+
curl -X GET https://api.example.com/example/1
104+
```
105+
106+
**Response (200 OK):**
107+
108+
```json
109+
{
110+
"id": 1,
111+
"name": "Example 1",
112+
"description": "This is the first example."
113+
}
114+
```
115+
116+
**Response (404 Not Found):**
117+
118+
```json
119+
{
120+
"error": "Resource not found"
121+
}
122+
```
123+
124+
### POST /example
125+
126+
Creates a new example resource.
127+
128+
**Request:**
129+
130+
```bash
131+
curl -X POST \
132+
https://api.example.com/example \
133+
-H 'Content-Type: application/json' \
134+
-d '{
135+
"name": "New Example",
136+
"description": "This is a new example."
137+
}'
138+
```
139+
140+
**Response (201 Created):**
141+
142+
```json
143+
{
144+
"id": 3,
145+
"name": "New Example",
146+
"description": "This is a new example."
147+
}
148+
```
149+
150+
### PUT /example/{id}
151+
152+
Updates an existing example resource by ID.
153+
154+
**Request:**
155+
156+
```bash
157+
curl -X PUT \
158+
https://api.example.com/example/1 \
159+
-H 'Content-Type: application/json' \
160+
-d '{
161+
"name": "Updated Example Name",
162+
"description": "This is an updated example."
163+
}'
164+
```
165+
166+
**Response (200 OK):**
167+
168+
```json
169+
{
170+
"id": 1,
171+
"name": "Updated Example Name",
172+
"description": "This is an updated example."
173+
}
174+
```
175+
176+
### DELETE /example/{id}
177+
178+
Deletes an example resource by ID.
179+
180+
**Request:**
181+
182+
```bash
183+
curl -X DELETE https://api.example.com/example/1
184+
```
185+
186+
**Response (204 No Content):**
187+
188+
(No content is returned)
189+
190+
## Error Examples
191+
192+
This section provides examples of common error responses.
193+
194+
**400 Bad Request:**
195+
196+
```json
197+
{
198+
"error": "Invalid input",
199+
"message": "The 'name' field is required."
200+
}
201+
```
202+
203+
**401 Unauthorized:**
204+
205+
```json
206+
{
207+
"error": "Unauthorized",
208+
"message": "Invalid API key."
209+
}
210+
```
211+
212+
**500 Internal Server Error:**
213+
214+
```json
215+
{
216+
"error": "Internal Server Error",
217+
"message": "An unexpected error occurred."
218+
}
219+
```

0 commit comments

Comments
 (0)