Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

6 watching

Forks

Repository files navigation

MassBank-export-api

A REST interface to export MassBank records to other formats.

This server was generated by the OpenAPI Generator project and uses Spring Boot. It uses the RecordParserDefinition from the original MassBank project.

Requirements

  • Java 25
  • Spring Boot 4.2
  • maven
  • PostgreSQL (tested on version 17)

Configuration

MassBank Data

This microservice is configured with environment variables. It requires a directory with the MassBank-data release. The default directory is ./MassBank-data; set MB_DATA_DIRECTORY to use a different location.

git clone https://github.com/MassBank/MassBank-data.git
export MB_DATA_DIRECTORY="$(realpath ./MassBank-data)"

CORS

To configure CORS you can set the environment variable CORS_ALLOWED_ORIGINS.

export CORS_ALLOWED_ORIGINS=http://localhost:3000

CONTEXT_PATH

The application serves the content at the given CONTEXT_PATH. If no CONTEXT_PATH is given the application serves at root path http://localhost:8080/. To serve the application at a different path set the environment variable CONTEXT_PATH, e.g. CONTEXT_PATH="/MassBank-export" and the server will listen on http://localhost:8080/MassBank-export.

Using a Reverse Proxy

To make the Swagger UI work behind a reverse proxy one must configure some X-Forward RequestHeader as descibed here. Here is an example for Apache:

RequestHeader set X-Forwarded-Prefix "/MassBank-export"
RequestHeader set X-Forwarded-Proto https
RequestHeader set X-Forwarded-Port 443

To make this work with a K8s nginx Ingress one needs to enable the property

use-forwarded-headers true

in the ingress-nginx-controller ConfigMap. The application context path can be configured with the environment variable CONTEXT_PATH. If not set / is used by default.

PostgreSQL

Make sure to have a PostgreSQL server installed and running on your system. The MassBank data will be stored there.

Both the REST API and the importer use these database settings when run directly:

Variable Default
DB_HOST localhost
DB_PORT 5432
DB_NAME records
DB_USER massbank_export_api_user
DB_PASSWORD massbank-export-api-password

Dev Container with Podman

Start the rootless API socket on the Linux host before opening the dev container:

systemctl --user start podman.socket

The default configuration in .devcontainer/devcontainer.json uses a local feature to start a temporary PostgreSQL 17 cluster inside the dev container. Place MassBank-data and MassBank-lib next to this repository before opening it; the configuration bind-mounts both directories.

The dev container mounts $XDG_RUNTIME_DIR/podman/podman.sock. Testcontainers uses that socket to start separate PostgreSQL containers on the host and reaches their published ports via host.containers.internal. The socket gives processes in the dev container control over the host user's Podman containers.

Build and Run

Build the service with Maven. The build runs tests, including integration tests that require a Docker-compatible container runtime (see the Podman setup above).

mvn clean package

This build creates two executable jars:

  • target/massbank-export-api-rest-api.jar
  • target/massbank-export-api-data-import.jar

Import the MassBank records into the configured PostgreSQL database once before starting the REST API:

java -jar target/massbank-export-api-data-import.jar

Run the REST API:

java -jar target/massbank-export-api-rest-api.jar

Run with Docker

Build and Run

Copy env.dist to .env and set MB_DATA_DIRECTORY to the host directory containing the MassBank data. DB_PORT changes only the published PostgreSQL port on the host; services always connect to PostgreSQL on port 5432 inside the Compose network. Set CONTEXT_PATH or CORS_ALLOWED_ORIGINS in .env to override the API defaults. Replace the sample database password before deploying.

docker compose pull postgres
docker compose build export-service
docker compose --profile import run --rm --no-build --pull never data-loader
docker compose up -d --no-build --pull never export-service

The importer starts PostgreSQL as a dependency and exits when the import finishes. Start the API after a successful import. To reload data, rerun the importer command.

Both services use one Docker image that contains two jars:

  • export-service runs /app-rest.jar
  • data-loader runs /app-import.jar

Use Pre-built Container

Pre-built Docker images are available from quay.io/massbank/massbank-export-api. After creating .env, import the data, then start the API:

docker compose --profile import run --rm --no-build --pull always data-loader
docker compose up -d --no-build --pull always export-service

Usage

For a description of how to use the api browse to the Swagger UI.

The database status can be checked with:

curl http://localhost:8080/database/status

For readiness checks use:

curl -i http://localhost:8080/database/ready

/database/ready returns HTTP 200 when the database is reachable and contains active MassBank records, otherwise HTTP 503.

For example, to download all MassBank records in one zip file use the following command:

curl -X 'POST' \
  'http://localhost:8080/convert' \
  -H 'accept: application/zip' \
  -H 'Content-Type: application/json' \
  -d '{
  "format": "massbank"
}' --output records.zip

Or, for example, to get a record's raw text use the following command:

curl -X 'GET' \
  'http://localhost:8080/rawtext/MSBNK-IPB_Halle-PB001341' \
  -H 'accept: text/plain' \
  -H 'Content-Type: application/json'

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

6 watching

Forks

Releases

Packages

Used by

Contributors

Languages