Skip to content

⚡ Starter API template for todo apps with user authentication in Python FastAPI

Notifications You must be signed in to change notification settings

afutofu/python-fastapi-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python FastAPI Starter

Starter implementation of authentication and todo RESTful APIs in Python FastAPI.

Access other branches to find more modular implementations of authentication and todo APIs:

Table of Contents

  1. Features
  2. Endpoints
  3. Setup
  4. Usage
  5. Access OpenAPI
  6. Authors

Features

  • 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

Endpoints

Authentication

  • POST /auth/register - Register a new user
  • POST /auth/token - Login a user
  • POST /auth/logout - Logout a user

Todo

  • POST /todos - Create a new todo
  • GET /todos - Get all todos
  • GET /todos/{id} - Get a todo by ID
  • PUT /todos/{id} - Update a todo by ID
  • DELETE /todos/{id} - Delete a todo by ID I

Setup

  1. Clone the repository:

    git clone https://github.com/afutofu/python-fastapi-starter.git
    cd python-fastapi-starter
  2. Install dependencies:

    pip install -r requirements.txt
  3. Run the server:

    uvicorn folder.main:app --reload

Usage

Authentication

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

Todo

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

Access OpenAPI UI

Navigate to:

http://localhost:8000/docs

OpenAPI (Swagger) UI

Authors

  • Afuza: Create and maintain repository

About

⚡ Starter API template for todo apps with user authentication in Python FastAPI

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages