REST API designed in FastAPI for Todo APP
- Environment
- Installation
- Run Server
- Root EndPoint
- Schema
- Todo Model
- End Points
- Documentation
- API Functions
To start the environment go to the terminal and type:
source venv/bin/activate
All the packages are installed on the environment
uvicorn archive-name:app --reload
http://127.0.0.1:8000/
You can change the port for whatever you want using:
--port=Number
- All API access is based on HTTP;
- All Data is in JSON type;
This is the schema used by now, date for creation and finalization of the todos will be used in the future.
{
"status": "OK",
"code": "200",
"message": "Fetched all data",
"result": [
{
"title": "string",
"category": "string",
"done": boolean,
"id": int
},
{
"title": "string",
"category": "string",
"done": boolean,
"id": int
}
]
}
Command | End Point | Description |
---|---|---|
GET | / | Get All Todos |
GET | /todos/{id_todo} | Get Todo By Id |
Delete | /todos/{id_todo} | Delete Todo |
Patch | /todos/finish/{id_todo} | Finishing Todo |
Patch | /todos/reopen/{id_todo} | Reopening Todo |
POST | /todos | Create todo |
GET | /highest_id | Get Highest Id on Database |
http://127.0.0.1:8000/docs
- GET /
- GET /todos/{todo_id}
- DELETE /todos/{todo_id}
- PATCH /todos/finish/{todo_id}
- PATCH /todos/reopen/{todo_id}
- POST /todos
- GET /highest_id
- Optional parameters:
- Skip: integer - Default = 0;
- Limit: integer - Default = 100;
- No request body
Curl
curl -X 'GET' \
'http://127.0.0.1:8000/' \
-H 'accept: application/json'
Request URL
http://127.0.0.1:8000/
Response body
{
"status": "OK",
"code": "200",
"message": "Fetched all data",
"result": [
{
"title": "string",
"category": "string",
"done": boolean,
"id": int
},
{
"title": "string",
"category": "string",
"done": boolean,
"id": int
}
]
}
Required:
- id_todo
Curl
curl -X 'GET' \
'http://127.0.0.1:8000/todo/{todo_id}' \
-H 'accept: application/json'
Request URL:
http://127.0.0.1:8000/todos/{todo_id}
Response:
{
"status": "OK",
"code": "200",
"message": "Fetched the selected data",
"result": {
"title": "string",
"category": "string",
"done": boolean,
"id": int
}
}
Required:
- todo_id: integer (path)
Curl
curl -X 'DELETE' \
'http://127.0.0.1:8000/todo/{todo_id}' \
-H 'accept: application/json' \
Request URL
http://127.0.0.1:8000/todo/{id_todo}
Response body
{
"status": "OK",
"code": "200",
"message": "Todo deleted",
"result": null
}
Request body:
{
"parameter": {
"id": int,
"title": "string",
"category": "string",
"done": true
}
}
Curl
curl -X 'PATCH' \
'http://127.0.0.1:8000/todos/{todo_id}' \
-H 'accept: application/json'
Request URL
http://127.0.0.1:8000/todos/finish/{todo_id}
Response body
{
"status": "Accepted",
"code": "202",
"message": "Todo is completed",
"result": {
"title": "asuhuash",
"category": "Work",
"done": true,
"id": 2
}
}
Request body:
{
"parameter": {
"id": int,
"title": "string",
"category": "string",
"done": true
}
}
Curl
curl -X 'PATCH' \
'http://127.0.0.1:8000/todos/reopen/{todo_id}' \
-H 'accept: application/json'
Request URL
http://127.0.0.1:8000/todos/reopen/{todo_id}
Response body
{
"status": "Accepted",
"code": "202",
"message": "Todo is reopened",
"result": {
"title": "asuhuash",
"category": "Work",
"done": false,
"id": 2
}
}
Request Body
{
"parameter": {
"id": int,
"title": "string",
"category": "string",
"done": true
}
}
Curl
curl -X 'POST' \
'http://localhost:8000/todos' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"parameter": {
"id": int,
"title": "string",
"category": "string",
"done": true
}
}'
Response body
{
"status": "Created Todo",
"code": "201",
"message": "Todo created successfully",
"result": null
}
- No parameters
Curl
curl -X 'GET' \
'http://localhost:8000/highest_id' \
-H 'accept: application/json'
Request URL:
http://localhost:8000/highest_id
Response body:
{
int
}
``