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.
- Java 21
- Spring Boot 3.5
- maven
- PostgreSQL (tested on version 17)
This microservice is configured with environment variables. It requires a
directory with the MassBank-data
release. This directory needs to be configured in the environment variable
MB_DATA_DIRECTORY.
git clone https://github.com/MassBank/MassBank-data.git
export MB_DATA_DIRECTORY="$(realpath ./MassBank-data)"To configure CORS you can set the environment variable CORS_ALLOWED_ORIGINS.
export CORS_ALLOWED_ORIGINS=http://localhost:3000The 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.
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 443To 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.
Make sure to have a PostgreSQL server installed and running on your system. The MassBank data will be stored there.
By default, the export service expects the PostgreSQL service running at localhost with port 5432 and the database records. Default user is massbank_export_api_user and password is massbank-export-api-password.
Build the service with Maven:
mvn clean packageThis build creates two executable jars:
target/massbank-export-api-rest-api.jartarget/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.jarRun the REST API:
java -jar target/massbank-export-api-rest-api.jarThe file docker-compose.yml provides the config to build and run the postgres database and the MassBank-export-api
with docker. Copy env.dist file to .env file and configure to your needs. Then build and run with:
docker compose up --buildThis starts PostgreSQL and the REST API service. The importer is available as a separate on-demand service profile.
Run the importer profile when you want to (re)load data:
docker compose --profile import up --build data-loaderBoth services use one Docker image that contains two jars:
export-serviceruns/app-rest.jardata-loaderruns/app-import.jar
Then start or restart the REST API:
docker compose up --build export-servicePre-built Docker images are available from
quay.io/massbank/massbank-export-api.
The fastest way to get things running after creating .env is:
docker compose upTo run only the importer from the pre-built image:
docker compose --profile import up data-loaderFor 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/statusFor 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.zipOr, 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'