Implemented using Flask microframework.
Clone the repo:
git clone https://github.com/PipeOpsHQ/titanic-api.git
cd titanic-apiUse venv or any other (Pipenv, Poetry, etc) environment management tool to install dependencies in the same folder. Activate virtual environment and run:
pip install -r requirements.txtThis API was tested using postgres. In order to bring it up, the following commands are needed:
- Start postgres locally with
docker run --net=host --name titanic-db -e POSTGRES_PASSWORD=password -e POSTGRES_USER=user -d postgres - Run the sql file with the database definition
docker cp titanic.sql titanic-db:/ - Run the sql file with
docker exec -it --rm titanic-db psql -U user -d postgres -f titanic.sql
After you have database server deployed and running, use environment variable DATABASE_URL to provide database connection string.
DATABASE_URL=postgresql+psycopg2://user:password@127.0.0.1:5432/postgres python run.pyGo to http://127.0.0.1:5000/ in your browser.
Test it by:
- See the database is currently empty with:
http://127.0.0.1:5000/people - Add a new user with
curl -H "Content-Type: application/json" -X POST localhost:5000/people -d'{"survived": 2,"passengerClass": 2,"name": "Mr. Owen Harris Braund","sex": "male","age": 22.0,"siblingsOrSpousesAboard": 4,"parentsOrChildrenAboard": 5,"fare": 7.25} - Check out if the user was added with
http://127.0.0.1:5000/people