
- Set up project structure with FastAPI - Implement user authentication system with JWT tokens - Create database models for users, notes, and collections - Set up SQLAlchemy ORM and Alembic migrations - Implement CRUD operations for notes and collections - Add filtering and sorting capabilities for notes - Implement health check endpoint - Update project documentation
3.8 KiB
3.8 KiB
Notes API
A RESTful API for managing notes with user authentication, collections/folders, and advanced filtering capabilities.
Features
- User authentication (sign up, login, logout)
- CRUD operations for notes
- Group notes into collections/folders
- Sort notes by various criteria (created date, updated date, title)
- Search notes by title and content
- Filter notes by collection, archived status, and date range
Tech Stack
- Backend: FastAPI
- Database: SQLite with SQLAlchemy ORM
- Authentication: JWT tokens with OAuth2
- Migrations: Alembic
Project Structure
.
├── alembic/ # Database migrations
├── app/
│ ├── api/ # API endpoints
│ │ └── v1/ # API version 1
│ ├── core/ # Core application settings
│ ├── crud/ # Database CRUD operations
│ ├── db/ # Database setup
│ ├── models/ # SQLAlchemy models
│ └── schemas/ # Pydantic schemas
├── storage/
│ └── db/ # SQLite database storage
├── .env # Environment variables
├── alembic.ini # Alembic configuration
├── main.py # Application entry point
└── requirements.txt # Project dependencies
Installation
- Clone the repository:
git clone <repository-url>
cd notes-api
- Install dependencies:
pip install -r requirements.txt
- Set up environment variables:
Create a .env
file in the root directory with the following variables:
SECRET_KEY=your-secret-key
CORS_ORIGINS=http://localhost:3000,http://localhost:8080
- Run database migrations:
alembic upgrade head
- Run the application:
uvicorn main:app --reload
The API will be available at http://localhost:8000.
API Documentation
Once the application is running, you can access the interactive API documentation at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
API Endpoints
Authentication
POST /api/v1/auth/register
- Register a new userPOST /api/v1/auth/login
- Log in and get access tokenGET /api/v1/auth/me
- Get current user information
Users
GET /api/v1/users/
- List all usersGET /api/v1/users/{user_id}
- Get user by IDGET /api/v1/users/me
- Get current userPUT /api/v1/users/me
- Update current user
Notes
GET /api/v1/notes/
- List notes with various filtering and sorting optionsPOST /api/v1/notes/
- Create a new noteGET /api/v1/notes/{id}
- Get a note by IDPUT /api/v1/notes/{id}
- Update a noteDELETE /api/v1/notes/{id}
- Delete a note
Collections
GET /api/v1/collections/
- List all collectionsPOST /api/v1/collections/
- Create a new collectionGET /api/v1/collections/{id}
- Get a collection by IDPUT /api/v1/collections/{id}
- Update a collectionDELETE /api/v1/collections/{id}
- Delete a collectionGET /api/v1/collections/{id}/notes
- Get all notes in a collection
Health Check
GET /health
- Check API health status
Notes API Query Parameters
The Notes API (GET /api/v1/notes/
) supports the following query parameters for filtering and sorting:
skip
: Number of items to skip (pagination)limit
: Maximum number of items to return (pagination)sort_by
: Field to sort by (created_at
,updated_at
,title
)sort_order
: Sort order (asc
,desc
)search
: Search term for title and contentarchived
: Filter by archived status (true
,false
)collection_id
: Filter by collection IDstart_date
: Filter notes created after this dateend_date
: Filter notes created before this date
License
MIT