A production-ready CRUD (Create, Read, Update, Delete) application built with FastAPI and PostgreSQL, designed for deployment on Render.
- ✅ Full CRUD operations for items
- ✅ FastAPI with automatic API documentation
- ✅ PostgreSQL database integration
- ✅ SQLAlchemy ORM
- ✅ Pydantic data validation
- ✅ CORS enabled
- ✅ Health check endpoint
- ✅ Ready for Render deployment
| Method | Endpoint | Description |
|---|---|---|
| GET | / | API welcome message |
| GET | /health | Health check |
| POST | /items/ | Create a new item |
| GET | /items/ | Get all items (with pagination) |
| GET | /items/{item_id} | Get a specific item |
| PUT | /items/{item_id} | Update an item |
| DELETE | /items/{item_id} | Delete an item |
deployment/ ├── main.py # FastAPI application and endpoints ├── models.py # SQLAlchemy database models ├── schemas.py # Pydantic schemas for validation ├── database.py # Database configuration ├── requirements.txt # Python dependencies ├── render.yaml # Render deployment configuration ├── .env.example # Environment variables template ├── .gitignore # Git ignore file └── README.md # This file - Python 3.11+
- PostgreSQL 12+
- Clone the repository and navigate to the project directory:
cd "C:\F-Drive\AI-agent-call\LPO Automation\deployment"- Create a virtual environment:
python -m venv venv # Windows venv\Scripts\activate # Linux/Mac source venv/bin/activate- Install dependencies:
pip install -r requirements.txt- Set up environment variables:
# Copy the example env file cp .env.example .env # Edit .env with your database credentials- Create PostgreSQL database:
CREATE DATABASE crud_db;- Run the application:
uvicorn main:app --reloadThe API will be available at http://localhost:8000
Once the application is running, you can access:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
-
Push your code to a Git repository (GitHub, GitLab, or Bitbucket)
-
Go to Render Dashboard
-
Click "New" → "Blueprint"
-
Connect your repository
-
Render will automatically detect
render.yamland create:- A PostgreSQL database
- A web service running your FastAPI app
-
Create PostgreSQL Database:
- Go to Render Dashboard
- Click "New" → "PostgreSQL"
- Choose a name (e.g.,
crud-db) - Select the free plan
- Click "Create Database"
- Copy the "Internal Database URL"
-
Create Web Service:
- Click "New" → "Web Service"
- Connect your repository
- Configure:
- Name: crud-api
- Environment: Python 3
- Build Command:
pip install -r requirements.txt - Start Command:
uvicorn main:app --host 0.0.0.0 --port $PORT
- Add Environment Variable:
- Key:
DATABASE_URL - Value: (paste the Internal Database URL from step 1)
- Key:
- Click "Create Web Service"
curl -X POST "http://localhost:8000/items/" \ -H "Content-Type: application/json" \ -d '{ "title": "My First Item", "description": "This is a test item", "completed": false }'curl "http://localhost:8000/items/"curl "http://localhost:8000/items/1"curl -X PUT "http://localhost:8000/items/1" \ -H "Content-Type: application/json" \ -d '{ "title": "Updated Item", "completed": true }'curl -X DELETE "http://localhost:8000/items/1"id(Integer): Auto-generated primary keytitle(String): Item title (required)description(String): Item description (optional)completed(Boolean): Completion status (default: false)created_at(DateTime): Timestamp when createdupdated_at(DateTime): Timestamp when last updated
| Variable | Description | Default |
|---|---|---|
| DATABASE_URL | PostgreSQL connection string | postgresql://postgres:postgres@localhost:5432/crud_db |
- FastAPI: Modern, fast web framework for building APIs
- PostgreSQL: Powerful, open-source relational database
- SQLAlchemy: SQL toolkit and ORM
- Pydantic: Data validation using Python type annotations
- Uvicorn: Lightning-fast ASGI server
MIT License - feel free to use this project for learning or production!
For issues or questions, please check the FastAPI documentation: https://fastapi.tiangolo.com/