Starter implementation of authentication and todo RESTful APIs in Python FastAPI.
Access other branches to find more modular implementations of authentication and todo APIs:
- User registration
- User login
- User logout
- Create a todo
- Get all todos
- Get a todo by ID
- Update a todo by ID
- Delete a todo by ID
POST /auth/register
- Register a new userPOST /auth/token
- Login a userPOST /auth/logout
- Logout a user
POST /todos
- Create a new todoGET /todos
- Get all todosGET /todos/{id}
- Get a todo by IDPUT /todos/{id}
- Update a todo by IDDELETE /todos/{id}
- Delete a todo by ID I
-
Clone the repository:
git clone https://github.com/afutofu/python-fastapi-starter.git cd python-fastapi-starter
-
Install dependencies:
pip install -r requirements.txt
-
Run the server:
uvicorn folder.main:app --reload
Register a user:
curl -X POST http://localhost:8000/auth/register -H "Content-Type: application/json" -d '{"username":"testuser", "password":"password123"}'
Login:
curl -X POST http://localhost:8000/auth/token -H "Content-Type: application/json" -d '{"username":"testuser", "password":"password123"}'
Logout user:
curl -X POST http://localhost:8000/auth/logout
For each of the following, include the header "Authorization: Bearer x". Where x is the access token received from the server via the /auth/token route
Create a Todo:
curl -X POST http://localhost:8000/todos -H "Content-Type: application/json" -d '{"text":"Test Todo", "completed":false}'
Get All Todos:
curl -X GET http://localhost:8000/todos
Get a Todo by ID:
curl -X GET http://localhost:8000/todos/1
Update a Todo by ID:
curl -X PUT http://localhost:8000/todos/1 -H "Content-Type: application/json" -d '{"text":"Updated Todo", "completed":true}'
Delete a Todo by ID:
curl -X DELETE http://localhost:8000/todos/1
Navigate to:
http://localhost:8000/docs
- Afuza: Create and maintain repository