Skip to content

devasconceloss/Todo-API

Repository files navigation

Todo API

REST API designed in FastAPI for Todo APP

Environment

To start the environment go to the terminal and type:

source venv/bin/activate

Installation:

All the packages are installed on the environment

Run Server:

uvicorn archive-name:app --reload

Root EndPoint

http://127.0.0.1:8000/

You can change the port for whatever you want using:

--port=Number

Schema

  • All API access is based on HTTP;
  • All Data is in JSON type;

Todo Model

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
        }
    ]
}

End Points

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

Documentation

http://127.0.0.1:8000/docs

API Functions

GET /

  • 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
        }
    ]
}

GET /todos/{todo_id}

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
  }
}

DELETE /todos/{todo_id}

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
}

PATCH /todos/finish/{todo_id}

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
  }
}

PATCH /todos/reopen/{todo_id}

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
  }
}

POST /todos

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
}

GET /highest_id

  • 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
}
``