Skip to content

Latest commit

Β 

History

History
89 lines (67 loc) Β· 2.16 KB

File metadata and controls

89 lines (67 loc) Β· 2.16 KB

Professional FastAPI CRUD API with JWT Authentication (SQLite)

This is a production-ready REST API project built with FastAPI and SQLite, following industry-standard structure. The API supports:

  • JWT-based Authentication
  • Password Hashing (bcrypt)
  • CRUD Operations on Items
  • SQLite as lightweight backend DB

πŸš€ Project Structure

api_project/ β”‚ β”œβ”€β”€ app/ β”‚ β”œβ”€β”€ main.py # Entry Point β”‚ β”œβ”€β”€ models.py # SQLAlchemy Models β”‚ β”œβ”€β”€ schemas.py # Pydantic Schemas β”‚ β”œβ”€β”€ database.py # Database Connection β”‚ β”œβ”€β”€ crud.py # DB Operations β”‚ β”œβ”€β”€ auth.py # Authentication Helpers β”‚ β”œβ”€β”€ routers/ β”‚ β”‚ β”œβ”€β”€ user.py # User Routes (Register/Login) β”‚ β”‚ └── item.py # Item CRUD Routes β”‚ └── core/ β”‚ └── security.py # JWT + Password Hashing β”‚ β”œβ”€β”€ requirements.txt β”œβ”€β”€ .env # Secret Config (Optional) β”œβ”€β”€ .gitignore └── README.md


βš™οΈ Installation

# 1️⃣ Clone the repository
git clone https://github.com/AKJilani/FastAPI_SQLite.git
cd FastAPI_SQLite

# 2️⃣ Create virtual environment
python -m venv venv
source venv/bin/activate    # For Linux/Mac
# venv\Scripts\activate     # For Windows

# 3️⃣ Install dependencies
pip install -r requirements.txt

# 4️⃣ Run the server
uvicorn app.main:app --reload

πŸ” Authentication Flow
POST /api/users/register : Create User

POST /api/users/login : Obtain JWT Token (Bearer)

Use the token in Authorization headers:

makefile
Copy
Edit
Authorization: Bearer your_token_here
πŸ“‘ API Endpoints
Endpoint	Method	Description
/api/users/register	POST	Register User
/api/users/login	POST	Login & get JWT
/api/items/	POST	Create Item
/api/items/	GET	Get All Items
/api/items/{id}	GET	Get Item by ID
/api/items/{id}	PUT	Update Item by ID
/api/items/{id}	DELETE	Delete Item by ID

Swagger Docs available at:
πŸ“„ http://127.0.0.1:8000/docs

πŸ“¦ Production Deployment
Use uvicorn with gunicorn or hypercorn

Store sensitive config in .env file

Use a reverse proxy (Nginx, Caddy)

Serve React frontend separately or as static files

πŸ“œ License
This project is open source and free to use under the MIT License.