项目作者: jkogut

项目描述 :
Simple python rest-api with docker-compose, tests and travis-ci
高级语言: Python
项目地址: git://github.com/jkogut/simple-python-rest-api-v2.git
创建时间: 2018-10-28T11:12:12Z
项目社区:https://github.com/jkogut/simple-python-rest-api-v2

开源协议:MIT License

下载


simple-python-rest-api-v2

Simple python REST API v2 with docker and travis-ci

Build Status
MIT license

Install

clone the repo first and then build the docker images and run it

  1. docker-compose up -d

test it with py.test

  1. py.test -v -l test_rest_api_docker.py

Test

Test available endpoints with curl

Example usage:

  1. curl http://0.0.0.0:5002/api/status |jq
  2. curl http://0.0.0.0:5002/api/v1/passengers |jq
  3. curl http://0.0.0.0:5002/api/v1/passengers/234 |jq
  4. curl http://0.0.0.0:5002/api/v1/passengers/survived/1 |jq
  5. curl -H "Content-Type: application/json" -X POST -d@payload.json http://0.0.0.0:5002/api/v1/passengers/new |jq
  6. curl -X DELETE http://0.0.0.0:5002/api/v1/passengers/delete/887 |jq

Debug

Clone the repo:

  1. git clone git@github.com:jkogut/simple-python-rest-api-v1.git

Use virtualenv and install dependencies with pip:

  1. virtualenv venv
  2. source venv/bin/activate
  3. pip install -r app/requirements.txt

In docker-compose.yml file:

  1. Comment out whole rest-api-service section and allow communication with MariaDB by uncommenting ports section in mariadb-service.

  2. Run mariadb-service and normalize-db-service containers with docker compose: docker-compose up

  3. Edit mysqlConf variable and replace mariadb-service to 0.0.0.0 in app/rest_server.py file.

  4. Run flask rest application in debug mode:

    1. cd app;
    2. python rest_server.py