A RESTful API built with FastAPI and PostgreSQL for managing posts.
- ✅ Create, Read, Update, Delete (CRUD) operations
- ✅ PostgreSQL database with SQLAlchemy ORM
- ✅ Pydantic schemas for data validation
- ✅ Auto-generated API documentation
- Clone the repository
git clone <your-repo-url>
cd <repo-name>- Create virtual environment
python -m venv venv- Activate virtual environment
# Windows PowerShell
.\venv\Scripts\Activate.ps1
# Windows CMD
.\venv\Scripts\activate.bat
# Mac/Linux
source venv/bin/activate- Install dependencies
pip install -r requirements.txt- Create
.envfile
# Create .env file in the root directory
DATABASE_URL=postgresql://username:password@localhost:5432/database_name
SECRET_KEY=your-secret-key-here- Run the application
uvicorn main:app --reload| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Welcome message |
| GET | /posts |
Get all posts |
| POST | /posts |
Create a new post |
| GET | /posts/{id} |
Get post by ID |
| PUT | /posts/{id} |
Update post by ID |
| DELETE | /posts/{id} |
Delete post by ID |
After running the app, visit:
- Swagger UI: http://127.0.0.1:8000/docs
- ReDoc: http://127.0.0.1:8000/redoc
- FastAPI
- PostgreSQL
- SQLAlchemy
- Pydantic
- Uvicorn