User Management API A simple REST API for managing users, built with FastAPI, SQLAlchemy, and JWT authentication.
Tech Stack FastAPI – web framework SQLAlchemy – ORM with SQLite passlib (sha256_crypt) – password hashing python-jose – JWT token generation
Setup bash pip install fastapi sqlalchemy passlib python-jose uvicorn bash uvicorn main:app --reload
API will be available at http://127.0.0.1:8000
Interactive docs at http://127.0.0.1:8000/docs
Endpoints
| Method | Endpoint | Auth | Description |
|---|---|---|---|
| GET | / |
No | API info |
| POST | /users |
No | Register a new user |
| POST | /login |
No | Login, returns JWT token |
| GET | /users/me |
Yes | Get current user |
| GET | /users |
No | List all users |
| GET | /users/{id} |
Yes | Get user by ID |
| PUT | /users/{id} |
No | Update user |
| DELETE | /user/{id} |
No | Delete user |
Authentication
Login returns a Bearer token. Pass it in the Authorization header for protected routes:
Authorization: Bearer
Tokens expire after 30 minutes
Project Structure
├── main.py # Routes ├── auth.py # JWT + password logic ├── models.py # Database models ├── schemas.py # Pydantic schemas ├── database.py # DB setup