https://github.com/ahmed-gelemli/api-flask-project
This is a simple Flask app that provides an API to manage students. The app uses PostgreSQL as a database to store student information.
https://github.com/ahmed-gelemli/api-flask-project
flask postgresql python3 restful-api
Last synced: about 2 months ago
JSON representation
This is a simple Flask app that provides an API to manage students. The app uses PostgreSQL as a database to store student information.
- Host: GitHub
- URL: https://github.com/ahmed-gelemli/api-flask-project
- Owner: ahmed-gelemli
- Created: 2023-04-27T12:43:39.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2025-04-30T22:44:59.000Z (about 1 year ago)
- Last Synced: 2025-06-24T18:49:34.736Z (about 1 year ago)
- Topics: flask, postgresql, python3, restful-api
- Language: HTML
- Homepage:
- Size: 539 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Flask Students API
This is a simple Flask app that provides an API to manage students. The app uses PostgreSQL as a database to store student information.
## Requirements
You'll need the following installed on your system to run this app:
- Python 3.7 or later
- PostgreSQL
## Python Dependencies
To install the required Python dependencies, run the following command:
```bash
pip install Flask Flask-SQLAlchemy psycopg2 flask-cors
```
## Database Setup
Create a PostgreSQL database and a table with the following SQL command:
```sql
CREATE TABLE students (
id SERIAL PRIMARY KEY,
name VARCHAR(18) NOT NULL,
phone INTEGER NOT NULL,
gender VARCHAR(10) NOT NULL,
created INTEGER NOT NULL,
modified INTEGER
);
```
Make sure to update the `app.config['SQLALCHEMY_DATABASE_URI']` in the start of Flask app code with the correct connection string for your PostgreSQL database.
## Running the App
To run the Flask app in your local system, execute the following command:
```bash
python app.py
```
The app will start running on [http://127.0.0.1:5000/](http://127.0.0.1:5000/).
## API Endpoints
The following API endpoints are available:
- `GET /api/hello`: A simple "Hello" endpoint for testing
- `GET /api/students`: Fetch all students
- `POST /api/students`: Create a new student
- `GET /api/students/`: Fetch a specific student by ID
- `PUT /api/students/`: Update a specific student by ID
- `DELETE /api/students/`: Delete a specific student by ID
- `PATCH /api/students/`: Update a specific student partially by ID
- `GET /api/students/search`: Search for students by name or gender
## Web Views
Additionally, the app provides web views for managing students:
- `/`: Home page
- `/view`: List all students
- `/students/addNew`: Add a new student
- `/students/`: View a specific student by ID
- `/students/edit/`: Edit a specific student by ID
- `/api/docs`: API documentation