This example demonstrates how to build a RESTful API using FastAPI and sqlite-worker for thread-safe database operations.
- Complete CRUD operations (Create, Read, Update, Delete)
- Thread-safe database access
- Automatic database initialization with WAL mode
- Pydantic models for request/response validation
- Error handling and HTTP status codes
pip install fastapi uvicorn sqlite-worker# From the fastapi_integration directory
python main.py
# Or using uvicorn directly
uvicorn main:app --reloadThe API will be available at http://localhost:8000
Once running, visit:
- Swagger UI:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
curl -X POST "http://localhost:8000/users" \
-H "Content-Type: application/json" \
-d '{"name": "Alice", "email": "alice@example.com", "age": 30}'curl "http://localhost:8000/users"curl "http://localhost:8000/users/1"curl -X PUT "http://localhost:8000/users/1" \
-H "Content-Type: application/json" \
-d '{"name": "Alice Smith", "age": 31}'curl -X DELETE "http://localhost:8000/users/1"- Thread Safety: sqlite-worker handles concurrent requests safely
- Simple API: Clean and intuitive ORM-like interface
- Production Ready: WAL mode and proper PRAGMA settings
- Error Handling: Proper HTTP status codes and error messages
- Add authentication and authorization
- Implement pagination for large datasets
- Add filtering and search capabilities
- Use database migrations for schema changes