Skip to content

Dhia0Eddine/Learn-flask

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 

Repository files navigation

Flask REST API with PostgreSQL

This is a simple RESTful API built using Flask and PostgreSQL with SQLAlchemy ORM. It includes endpoints to create, read, update, and delete (CRUD) venue data, and it's ready for extension with additional resources like users. The project can use Alembic for database migrations.


Project Structure

Flask_app/
โ”œโ”€โ”€ app.py             # Main Flask app with API routes
โ”œโ”€โ”€ config.py          # Configuration settings (including DB URI)
โ”œโ”€โ”€ models.py          # SQLAlchemy models and serialization
โ”œโ”€โ”€ migration/        # Alembic migration scripts (created later)
โ”œโ”€โ”€ alembic.ini        # Alembic configuration file
โ””โ”€โ”€ README.md          # Project documentation

Requirements

Install required packages in your virtual environment:

pip install -r requirements.txt

โš™๏ธ Configuration

config.py defines the database connection


๐Ÿ”ง Models

Defined in models.py. Example: Venue model with serialize() method for JSON response.


๐Ÿš€ Running the App

Start the app (after activating your virtual environment):

flask run or python app.py

๐Ÿ“ฎ API Endpoints

Method Endpoint Description
GET / Health check
POST /venues Create a new venue
GET /venues Get all venues
GET /venues/<id> Get a single venue
PUT /venues/<id> Update a venue
DELETE /venues/<id> Delete a venue

๐Ÿงช Testing with Postman

You can use Postman to send requests to http://localhost:5000.

๐Ÿงช Example POST Request (Postman)

POST Request Screenshot POST Response Screenshot

๐Ÿงฑ Alembic Migrations (Optional)

If using raw Alembic:

  1. Initialize:

    alembic init migrations
  2. Configure alembic.ini with your database URI or modify env.py to import from Config.

  3. Create and apply migration:

    alembic revision --autogenerate -m "Create Venue table"
    alembic upgrade head

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published