init
This commit is contained in:
185
doc/api.md
Normal file
185
doc/api.md
Normal file
@@ -0,0 +1,185 @@
|
||||
|
||||
# 📄 API Documentation – **Stupid APIs**
|
||||
|
||||
## Base URL
|
||||
|
||||
```
|
||||
http://localhost:3000
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 1️⃣ POST `/sort`
|
||||
|
||||
Sorts an array (numeric or alphabetical) and returns the sorted array.
|
||||
|
||||
### Request
|
||||
|
||||
**URL:**
|
||||
|
||||
```
|
||||
POST /sort
|
||||
```
|
||||
|
||||
**Headers:**
|
||||
|
||||
```
|
||||
Content-Type: application/json
|
||||
```
|
||||
|
||||
**Body Example:**
|
||||
|
||||
```json
|
||||
{
|
||||
"array": [3, 1, 4, 1, 5, 9]
|
||||
}
|
||||
```
|
||||
|
||||
### Successful Response
|
||||
|
||||
```json
|
||||
{
|
||||
"sortedArray": [1, 1, 3, 4, 5, 9]
|
||||
}
|
||||
```
|
||||
|
||||
### Error Responses
|
||||
|
||||
| Status Code | Description |
|
||||
| ----------- | ----------------------------------------------- |
|
||||
| `400` | Request body missing or `array` is not an array |
|
||||
| `500` | Unexpected server error |
|
||||
|
||||
---
|
||||
|
||||
## 2️⃣ POST `/is-odd`
|
||||
|
||||
Checks if a given number is odd.
|
||||
|
||||
### Request
|
||||
|
||||
**URL:**
|
||||
|
||||
```
|
||||
POST /is-odd
|
||||
```
|
||||
|
||||
**Headers:**
|
||||
|
||||
```
|
||||
Content-Type: application/json
|
||||
```
|
||||
|
||||
**Body Example:**
|
||||
|
||||
```json
|
||||
{
|
||||
"number": 7
|
||||
}
|
||||
```
|
||||
|
||||
### Successful Response
|
||||
|
||||
```json
|
||||
{
|
||||
"number": 7,
|
||||
"isOdd": true
|
||||
}
|
||||
```
|
||||
|
||||
**Example with an even number:**
|
||||
|
||||
```json
|
||||
{
|
||||
"number": 4,
|
||||
"isOdd": false
|
||||
}
|
||||
```
|
||||
|
||||
### Error Responses
|
||||
|
||||
| Status Code | Description |
|
||||
| ----------- | ------------------------------------------------------ |
|
||||
| `400` | Request body missing or `number` is not a valid number |
|
||||
| `500` | Unexpected server error |
|
||||
|
||||
---
|
||||
|
||||
## 3️⃣ POST `/is-even`
|
||||
|
||||
Checks if a given number is even.
|
||||
|
||||
### Request
|
||||
|
||||
**URL:**
|
||||
|
||||
```
|
||||
POST /is-even
|
||||
```
|
||||
|
||||
**Headers:**
|
||||
|
||||
```
|
||||
Content-Type: application/json
|
||||
```
|
||||
|
||||
**Body Example:**
|
||||
|
||||
```json
|
||||
{
|
||||
"number": 4
|
||||
}
|
||||
```
|
||||
|
||||
### Successful Response
|
||||
|
||||
```json
|
||||
{
|
||||
"number": 4,
|
||||
"isEven": true
|
||||
}
|
||||
```
|
||||
|
||||
**Example with an odd number:**
|
||||
|
||||
```json
|
||||
{
|
||||
"number": 7,
|
||||
"isEven": false
|
||||
}
|
||||
```
|
||||
|
||||
### Error Responses
|
||||
|
||||
| Status Code | Description |
|
||||
| ----------- | ------------------------------------------------------ |
|
||||
| `400` | Request body missing or `number` is not a valid number |
|
||||
| `500` | Unexpected server error |
|
||||
|
||||
---
|
||||
|
||||
## 📌 Example Usage with `curl`
|
||||
|
||||
### Sort an array (Linux/macOS)
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:3000/sort \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"array":[3,1,4,1,5,9]}'
|
||||
```
|
||||
|
||||
### Check if odd
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:3000/is-odd \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"number":7}'
|
||||
```
|
||||
|
||||
### Check if even
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:3000/is-even \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"number":4}'
|
||||
```
|
||||
Reference in New Issue
Block a user