Skip to content
Snippets Groups Projects

Engine API Server

Overview

The Project serves the Engine API and handles state management of multiple Engine instances.

This project is based on a swagger-enabled Flask server using an API First approach. It also uses the Connexion library on top of Flask.

Requirements

Python 3.7+ MariaDB (or similar Database)

Installation

Install the required dependencies:

pip3 install -r requirements.txt
# Additional requirements for the chosen database
pip3 install -r contrib/mariadb-requirements.txt
# Create database and user (change password in script)
sudo mysql -u root -p < contrib/mariadb-database.sql

Getting started

To run the server, please execute the following from the root directory:

./run.sh api

To run the API in an local development server execute:

./run.sh api-dev

Running with Docker

To run the server on a Docker container, please execute the following from the root directory:

# Building the image
./run.sh docker:build

# Push the current image to dockerhub.com
./run.sh docker:push

# Starting up a container
./run.sh docker:api

Using the API

Adding some entry to the playlog:

curl -d '{ "track_start": "2020-06-25 15:38:44", "track_artist": "Aphex Twin", "track_title": "Windowlicker", "log_source": 1 }' -H "Content-Type: application/json" -X POST http://localhost:8008/api/v1/playlog/store

The attribute log_source is a numeric presentation of the engine (1 or 2) where this log entry is coming from. If you are using additional audio sources, such as automated music player, you can define your own numeric id for such device.

All other API endpoints are listed in the interactive documentation:

http://localhost:8008/api/v1/ui/

Your OpenAPI definition lives here:

http://localhost:8008/api/v1/openapi.json

Testing

To launch the integration tests, use tox:

sudo pip install tox
./run.sh test

Note, the test-cases are currently not functional.