Skip to content

helaouichourouk/flask-rest-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flask RESTful API with PostgreSQL

This is a simple RESTful API built with Flask, Flask-RESTful, and PostgreSQL. It allows you to create and retrieve users.


🚀 Features

  • RESTful endpoints (GET, POST)
  • PostgreSQL database using SQLAlchemy ORM
  • Environment configuration via .env file
  • Docker-optional, production-ready structure

📁 Project Structure

flask-rest-api/
├── app.py
├── config.py
├── models.py
├── requirements.txt
├── .env
├── .gitignore
└── README.md

🔧 Prerequisites

  • Python 3.7+
  • PostgreSQL installed and running locally or in Docker
  • pip installed
  • [Optional] GitHub CLI (gh) for quick repo creation

🔐 Environment Variables

Create a .env file with your database credentials:

DATABASE_URL=postgresql://postgres\:yourpassword@localhost:5432/yourdbname

⚙️ Installation

Clone the repository

git clone https://github.com/helaouichourouk/flask-rest-api.git
cd flask-rest-api

Create a virtual environment

python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

Install dependencies

pip install -r requirements.txt

Create the database (via PostgreSQL CLI or pgAdmin)

CREATE DATABASE yourdbname;

▶️ Running the App

python app.py

The API will run at: http://127.0.0.1:5000/


📬 API Endpoints

GET /users

Returns a list of all users.

POST /users

Create a new user.

Request Body:

{
  "username": "chourouk",
  "email": "chourouk@example.com"
}

🗃️ Sample curl Commands

curl http://127.0.0.1:5000/users
curl -X POST http://127.0.0.1:5000/users \
-H "Content-Type: application/json" \
-d '{"username": "chourouk", "email": "chourouk@example.com"}'

🧹 .gitignore

# Python
__pycache__/
*.py[cod]
*.egg-info/
venv/

# Env vars
.env

🧑‍💻 Author

Chourouk Helaoui


📜 License

MIT License

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages