A RESTful API for managing notes with user authentication, built with FastAPI and PostgreSQL.
Base URL: https://notes-api-7zrq.onrender.com
Swagger UI: https://notes-api-7zrq.onrender.com/docs
- Signup —
POST /auth/signupwith email and password - Login —
POST /auth/login, copy theaccess_tokenfrom the response - Authorize — Click the 🔒 Authorize button in Swagger UI, paste the token
- Test Notes routes — All
/notesendpoints are now accessible
- FastAPI — API framework
- SQLAlchemy — ORM for database operations
- Alembic — Database migrations
- PostgreSQL (Supabase) — Database
- Pydantic — Request/response validation
- JWT (python-jose) — Authentication
- Passlib + bcrypt — Password hashing
notes-api/
├── main.py # App entry point
├── database.py # Engine, SessionLocal, Base, get_db
├── .env # Environment variables (not committed)
├── alembic/ # Migration files
├── models/
│ ├── note.py # SQLAlchemy Note model
│ └── user.py # SQLAlchemy User model
├── schemas/
│ ├── note.py # Pydantic NoteSchema
│ └── user.py # Pydantic UserCreate, UserResponse, LoginSchema
├── routers/
│ ├── notes.py # Note route handlers
│ └── auth.py # Auth route handlers
└── services/
├── note_service.py # Note DB logic
└── auth_service.py # Password hashing, JWT creation
git clone https://github.com/darshanr27/notes-api
cd notes-apipython -m venv venv
# Mac/Linux
source venv/bin/activate
# Windows
venv\Scripts\activatepip install fastapi sqlalchemy alembic pydantic python-jose passlib bcrypt==4.0.1 passlib==1.7.4 python-dotenv psycopg2-binary uvicornCreate a .env file in the project root:
DATABASE_URL=postgresql://postgres:yourpassword@db.xxxx.supabase.co:5432/postgres
SECRET_KEY=your_random_secret_key
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRY_MINUTES=30
Generate a secure SECRET_KEY:
openssl rand -hex 32alembic upgrade headfastapi dev main.pyAPI runs at http://localhost:8000
Swagger UI at http://localhost:8000/docs
| Method | Route | Description |
|---|---|---|
| POST | /auth/signup |
Register a new user |
| POST | /auth/login |
Login and receive JWT token |
| Method | Route | Description |
|---|---|---|
| POST | /notes |
Create a new note |
| GET | /notes |
Get all notes (optional ?title= filter) |
| GET | /notes/{id} |
Get a single note by id |
| PUT | /notes/{id} |
Update a note |
| DELETE | /notes/{id} |
Delete a note |
POST /auth/signup
{
"email": "user@example.com",
"password": "yourpassword"
}POST /auth/login
{
"email": "user@example.com",
"password": "yourpassword"
}Response:
{
"access_token": "eyJ...",
"token_type": "bearer"
}POST /notes
{
"id": 1,
"title": "My first note",
"content": "Some content here",
"created_at": "2024-01-15T10:00:00"
}# Create a new migration after model changes
alembic revision --autogenerate -m "description"
# Apply migrations
alembic upgrade head
# Rollback one step
alembic downgrade -1
# Check current version
alembic current