Simple python rest-api with docker-compose, tests and travis-ci
Simple python REST API v2 with docker and travis-ci
clone the repo first and then build the docker images and run it
docker-compose up -d
test it with py.test
py.test -v -l test_rest_api_docker.py
Test available endpoints with curl
Example usage:
curl http://0.0.0.0:5002/api/status |jq
curl http://0.0.0.0:5002/api/v1/passengers |jq
curl http://0.0.0.0:5002/api/v1/passengers/234 |jq
curl http://0.0.0.0:5002/api/v1/passengers/survived/1 |jq
curl -H "Content-Type: application/json" -X POST -d@payload.json http://0.0.0.0:5002/api/v1/passengers/new |jq
curl -X DELETE http://0.0.0.0:5002/api/v1/passengers/delete/887 |jq
Clone the repo:
git clone git@github.com:jkogut/simple-python-rest-api-v1.git
Use virtualenv
and install dependencies with pip
:
virtualenv venv
source venv/bin/activate
pip install -r app/requirements.txt
In docker-compose.yml
file:
Comment out whole rest-api-service section and allow communication with MariaDB by uncommenting ports section in mariadb-service.
Run mariadb-service and normalize-db-service containers with docker compose: docker-compose up
Edit mysqlConf
variable and replace mariadb-service to 0.0.0.0 in app/rest_server.py
file.
Run flask rest application in debug mode
:
cd app;
python rest_server.py