This is a simple RESTful API built with Flask, Flask-RESTful, and PostgreSQL. It allows you to create and retrieve users.
- RESTful endpoints (
GET,POST) - PostgreSQL database using SQLAlchemy ORM
- Environment configuration via
.envfile - Docker-optional, production-ready structure
flask-rest-api/
├── app.py
├── config.py
├── models.py
├── requirements.txt
├── .env
├── .gitignore
└── README.md- Python 3.7+
- PostgreSQL installed and running locally or in Docker
pipinstalled- [Optional] GitHub CLI (
gh) for quick repo creation
Create a .env file with your database credentials:
DATABASE_URL=postgresql://postgres\:yourpassword@localhost:5432/yourdbnamegit clone https://github.com/helaouichourouk/flask-rest-api.git
cd flask-rest-apipython -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install -r requirements.txtCREATE DATABASE yourdbname;python app.pyThe API will run at: http://127.0.0.1:5000/
Returns a list of all users.
Create a new user.
Request Body:
{
"username": "chourouk",
"email": "chourouk@example.com"
}curl http://127.0.0.1:5000/userscurl -X POST http://127.0.0.1:5000/users \
-H "Content-Type: application/json" \
-d '{"username": "chourouk", "email": "chourouk@example.com"}'# Python
__pycache__/
*.py[cod]
*.egg-info/
venv/
# Env vars
.envChourouk Helaoui
MIT License