Skip to content

jorgecodelia/apiFlaskExample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Example Python flask Rest API

Overview

This documentation outlines the endpoints available in the example REST API built with flask and python. GIT

Dependencies

More details here

Resource Documentation
python https://www.python.org/
pytest https://docs.pytest.org/en/8.0.x/
pytest-html https://docs.pytest.org/en/8.0.x/
flask https://flask.palletsprojects.com/en/3.0.x/
flask-restx https://flask-restx.readthedocs.io/en/latest/
flask-SQLAlchemy https://flask-sqlalchemy.palletsprojects.com/en/3.1.x/
Swagger https://swagger.io/
pyyaml https://pypi.org/project/PyYAML/
python-dotenv https://pypi.org/project/python-dotenv/

Project Structure

The project structure is organized as follows:

├── app/
│   ├── api/
│   │   ├── controller/
│   │   ├── exception/
│   │   ├── model/
│   │   ├── repository/
│   │   ├── service/
│   │   └── util/
│   ├── resources/
│   └── test/
│
├── ci/
│   ├── deploy/
│   ├── docker/
│   └── kubernates/
│
├── README.md
├── requirements.txt
├── .flaskenv
└── .gitignore

Base URL

The base URL for all endpoints is http://localhost:5000/v1/user.

API Endpoints

The following endpoints are available:

  • POST /v1/users: create user.
curl --location 'http://localhost:5000/v1/user' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "Charles",
    "email": "[email protected]"
}'
  • GET /v1/users: Get all users.
curl --location 'http://localhost:5000/v1/users'
  • GET /v1/user/123: Get a user by ID.
curl --location 'http://localhost:5000/v1/user?id=4'
  • PUT /v1/user: Update a user by ID.
curl --location --request PUT 'http://localhost:5000/v1/user?id=3' \
--header 'Content-Type: application/json' \
--data-raw '{
    "id": 3,
    "name": "Mike",
    "email": "[email protected]"
}'
  • DELETE /v1/user/123: Delete a user by ID.
curl --location --request DELETE 'http://localhost:5000/v1/user?id=4'

Endpoint Documentation

The openApi URL documentation in local environment is http://localhost:5000/api-doc.html.

Install

  • Step 1:
python -m venv env
  • Step 2:
source env/bin/activate
  • Step 3:
pip install -r requirements.txt
  • Step 4:
pip install -e .

Run unit test

Report URL

pytest

Run

flask run

License

This Api is distributed under the terms of the MIT License. See the license for details.

About

Python Flask Rest API example

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published