This is a minimalistic ready-to-go API backend using Flask.
- poetry
- make (to ease if docker to be used for development/testing)
Rename and set environment variables:
.example.env
->.env
- development server.example.testenv
->.testenv
- testing setup
For docker setup there are specific configuration files (as redis setup is different):
.dockerenv
- for environment setup.dockertestenv
- for testing setup
Specific variables:
CELERY_BROKER_URL
- broker connection in format
redis://:password@hostname:port/db_number
CELERY_RESULT_BACKEND_URL
- backend connection in format
redis://:password@hostname:port/db_number
There are two possible ways of making development:
- Using virtual environment (created by poetry)
- Using docker
They can be taken alone or mixing together.
To have an instance up and running locally:
- Go to
poetry shell
- Init database:
manage db upgrade manage init
- Run worker (redis backend should be running - e.g.
$ redis-server
)
celery worker -A easyto_api.celery_app:app --loglevel=info
- Run development server (will be available at
http://127.0.0.1:5000/
orhttp://localhost:5000/
)
manage run
- Alternatively run gunicorn as wsgi server (available at
http://127.0.0.1:8000
)
gunicorn easyto_api.wsgi:app
- Go to
poetry shell
- You can use pytest, tox, as well as flake8 and black like
pytest tox tox -e lint flake8 black .
- Also you can use them from outside of shell:
poetry run pytest poetry run flake8 poetry run black .
Use make
from the root project directory (or you can take docker commands from Makefile):
- initializing the instance (backend will be available at
http://127.0.0.1:5000/
orhttp://localhost:5000/
):
(sudo) make init
- shutting down the instance:
(sudo) docker-compose down
- running all the tests (still not properly working):
(sudo) make test
- Login to get access and refresh tokens
curl -X POST -H "Content-Type: application/json" -d '{"username": "admin", "password": "password"}' http://localhost:5000/auth/login response: { "access_token": "%access_token%", "refresh_token": "%refresh_token%" }
- Make signed API call
curl -X GET -H "Content-Type: application/json" -H "Authorization: Bearer %access_token%" http://localhost:5000/api/v1/endpoint
- Get new access token using refresh token
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer %refresh_token%" http://localhost:5000/auth/refresh response: { "access_token": "%access_token%" }
- Revoke access token using access token
curl -X DELETE -H "Content-Type: application/json" -H "Authorization: Bearer %access_token%" http://localhost:5000/auth/revoke_access
- Revoke refresh token using refresh token
curl -X DELETE -H "Content-Type: application/json" -H "Authorization: Bearer %refresh_token%" http://localhost:5000/auth/revoke_refresh