Skip to content

yoggys/flask-rest-api

Repository files navigation

Flask REST API template

Project setup

Tested on Windows 10 with Python 3.10.4. If any error occurs, download and run the project in this version.

git clone https://github.com/yoggys/flask-rest-api
cd flask-rest-api
pip install -r requirements.txt
python run.py

Optional arguments

By default server run as 127.0.0.1:5000 in production mode.

usage: run.py [-h] [--host HOST] [--port PORT] [--dev]

options:
  -h, --help   show this help message and exit
  --host HOST  Host name
  --port PORT  Port number
  --dev        Run server in development mode

Example

python run.py --dev --host localhost --port 8080

Tests

# Run server, wait for 3 seconds to make sure server started and run tests
python run.py --dev & sleep 3 && pytest

Output

================================================== test session starts ===================================================
platform win32 -- Python 3.10.11, pytest-7.3.1, pluggy-1.0.0
rootdir: ...\flask-rest-api\tests
plugins: asyncio-0.21.0
asyncio: mode=strict
collected 7 items

tests.py .......                                                                                                    [100%]

=================================================== 7 passed in 2.19s ====================================================

Project structure

├── flask-rest-api
│   ├── core
│   │   ├── __init__.py
│   │   ├── setup.py
│   │   └── utils.py
│   ├── models
│   │   └── UserModel.py
│   ├── routes
│   │   └── UserRoute.py
│   ├── tests
│   │   └── tests.py
└── └── run.py

API

Users

Methods: GET, POST, DELETE

api/v1/users/ - Users list

Methods: GET, POST, PUT, PATCH, DELETE

api/v1/users/\<int:user_id\> - User by id

About

Flask REST API template with SQLAlchemy models.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages