Skip to content

codejay12/render_deploy

Repository files navigation

Simple CRUD API with FastAPI and PostgreSQL

A production-ready CRUD (Create, Read, Update, Delete) application built with FastAPI and PostgreSQL, designed for deployment on Render.

Features

  • ✅ 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

API Endpoints

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

Project Structure

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 

Local Development Setup

Prerequisites

  • Python 3.11+
  • PostgreSQL 12+

Installation

  1. Clone the repository and navigate to the project directory:
cd "C:\F-Drive\AI-agent-call\LPO Automation\deployment"
  1. Create a virtual environment:
python -m venv venv # Windows venv\Scripts\activate # Linux/Mac source venv/bin/activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Set up environment variables:
# Copy the example env file cp .env.example .env # Edit .env with your database credentials
  1. Create PostgreSQL database:
CREATE DATABASE crud_db;
  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:

Deploying to Render

Option 1: Using render.yaml (Blueprint)

  1. Push your code to a Git repository (GitHub, GitLab, or Bitbucket)

  2. Go to Render Dashboard

  3. Click "New" → "Blueprint"

  4. Connect your repository

  5. Render will automatically detect render.yaml and create:

    • A PostgreSQL database
    • A web service running your FastAPI app

Option 2: Manual Deployment

  1. 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"
  2. 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)
    • Click "Create Web Service"

Example API Usage

Create an Item

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  }'

Get All Items

curl "http://localhost:8000/items/"

Get Single Item

curl "http://localhost:8000/items/1"

Update an Item

curl -X PUT "http://localhost:8000/items/1" \ -H "Content-Type: application/json" \ -d '{  "title": "Updated Item",  "completed": true  }'

Delete an Item

curl -X DELETE "http://localhost:8000/items/1"

Data Model

Item

  • id (Integer): Auto-generated primary key
  • title (String): Item title (required)
  • description (String): Item description (optional)
  • completed (Boolean): Completion status (default: false)
  • created_at (DateTime): Timestamp when created
  • updated_at (DateTime): Timestamp when last updated

Environment Variables

Variable Description Default
DATABASE_URL PostgreSQL connection string postgresql://postgres:postgres@localhost:5432/crud_db

Technology Stack

  • 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

License

MIT License - feel free to use this project for learning or production!

Support

For issues or questions, please check the FastAPI documentation: https://fastapi.tiangolo.com/

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published