A FastAPI-based REST API for managing contacts with PostgreSQL database.
- CRUD operations for contacts
- Search contacts by name, surname, or email
- Get contacts with upcoming birthdays (next 7 days)
- Data validation using Pydantic
- Interactive API documentation (Swagger UI)
- Alternative API documentation (ReDoc)
- Python 3.12.1
- PostgreSQL 14+
- Clone the repository
- Install dependencies:
pip install -r requirements.txt-
Configure PostgreSQL:
- Install PostgreSQL if not installed:
brew install postgresql@14 - Start PostgreSQL service:
brew services start postgresql@14 - Create a database:
createdb contacts_db
- Install PostgreSQL if not installed:
-
Run the application:
uvicorn src.main:app --reloadGET /contacts- Get list of all contactsPOST /contacts- Create a new contactGET /contacts/{contact_id}- Get a specific contact by IDPUT /contacts/{contact_id}- Update an existing contactDELETE /contacts/{contact_id}- Delete a contact
GET /contacts/find?q={query}- Search contacts by name, surname, or emailGET /contacts/birthdays/next7days- Get contacts with birthdays in the next 7 days
The API implements strict data validation:
first_nameandlast_name: 2-50 charactersemail: Must be a valid email addressphone: 10-20 charactersbirthday: Valid date in YYYY-MM-DD formatadditional_data: Optional field
Example of valid contact data:
{
"first_name": "Іван",
"last_name": "Петренко",
"email": "ivan@example.com",
"phone": "0501234567",
"birthday": "1990-01-15",
"additional_data": "Додаткова інформація"
}After running the application, visit:
- Swagger UI:
http://localhost:8000/docs- Interactive documentation with the ability to test endpoints - ReDoc:
http://localhost:8000/redoc- Alternative documentation with better readability
- 404: Contact not found
- 422: Validation error (invalid data format)
- 500: Internal server error