/bananas-api

OpenTTD's content service API (BaNaNaS API)

Primary LanguagePythonGNU General Public License v2.0GPL-2.0

BaNaNaS API

GitHub License GitHub Tag GitHub commits since latest release

GitHub Workflow Status (Testing) GitHub Workflow Status (Publish Image) GitHub Workflow Status (Deployments)

GitHub deployments (Staging) GitHub deployments (Production)

This is the HTTP API for OpenTTD's content service, called BaNaNaS. It works together with bananas-server, which serves the in-game client.

See introduction.md for more documentation about the different BaNaNaS components and how they work together.

The API is documented on SwaggerHub.

Development

This API is written in Python 3.8 with aiohttp, and makes strong use of asyncio.

Running a local server

Dependencies

  • Python3.8 or higher.
  • tusd. For example, copy the tusd binary in your ~/.local/bin.

Preparing your venv

To start it, you are advised to first create a virtualenv:

python3 -m venv .env
.env/bin/pip install -r requirements.txt

Starting a local server

You can start the HTTP server by running:

.env/bin/python -m bananas_api --web-port 8080 --tusd-port 1080 --storage local --index local --user developer --client-file clients-development.yaml

This will start the API on port 8080 for you to work with locally.

Running via docker

docker build -t openttd/bananas-api:local .
export BANANAS_COMMON=$(pwd)/../bananas-common
mkdir -p "${BANANAS_COMMON}/local_storage" "${BANANAS_COMMON}/BaNaNaS"
docker run --rm -p 127.0.0.1:8080:80 -p 127.0.0.1:1080:1080 -v "${BANANAS_COMMON}/local_storage:/code/local_storage" -v "${BANANAS_COMMON}/BaNaNaS:/code/BaNaNaS" openttd/bananas-api:local

The mount assumes that bananas-server and this repository has the same parent folder on your disk, as both servers need to read the same local storage.

Files upload (tusd)

tusd runs on its own port (1080 by default), and listens on /new-package/files. With other words: the webserver does not forward that URL to tusd. This means that for clients, you need to contact two endpoints:

  • the web-port for everything except /new-package/files.
  • the tusd-port for /new-package/files.

In production the Load Balancer redirects the URLs to the right ports, but during development this is something to keep in mind.

bananas-frontend-cli for example allows you to define the web-endpoint and the tusd-endpoint.