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

  1. Clone the repository:
git clone <repository-url>
cd notes-api
  1. Install dependencies:
pip install -r requirements.txt
  1. 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
  1. Run database migrations:
alembic upgrade head
  1. 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:

API Endpoints

Authentication

  • POST /api/v1/auth/register - Register a new user
  • POST /api/v1/auth/login - Log in and get access token
  • GET /api/v1/auth/me - Get current user information

Users

  • GET /api/v1/users/ - List all users
  • GET /api/v1/users/{user_id} - Get user by ID
  • GET /api/v1/users/me - Get current user
  • PUT /api/v1/users/me - Update current user

Notes

  • GET /api/v1/notes/ - List notes with various filtering and sorting options
  • POST /api/v1/notes/ - Create a new note
  • GET /api/v1/notes/{id} - Get a note by ID
  • PUT /api/v1/notes/{id} - Update a note
  • DELETE /api/v1/notes/{id} - Delete a note

Collections

  • GET /api/v1/collections/ - List all collections
  • POST /api/v1/collections/ - Create a new collection
  • GET /api/v1/collections/{id} - Get a collection by ID
  • PUT /api/v1/collections/{id} - Update a collection
  • DELETE /api/v1/collections/{id} - Delete a collection
  • GET /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 content
  • archived: Filter by archived status (true, false)
  • collection_id: Filter by collection ID
  • start_date: Filter notes created after this date
  • end_date: Filter notes created before this date

License

MIT

Description
Project: Notes API
Readme 51 KiB
Languages
Python 98.3%
Mako 1.7%