COMBINE-API is an HTTP API for working with COMBINE/OMEX archives and other COMBINE formats, such as the OMEX manifest, OMEX metadata, and SED-ML formats and several model formats such as BNGL, CellML, LEMS, NeuroML, RBA XML, SBML, Smoldyn, and XPP. This API is specified using OpenAPI and implemented in Python using connexion. This API is currently deployed at https://combine.api.biosimulations.org and https://combine.api.biosimulations.dev.
The specifications of the API were developed using Apicurio studio, a free web-based application for building OpenAPI-compliant specifications for HTTP APIs. The specifications of the API should be edited using Apicurio studio, exported from Apicurio in YAML format, and saved to combine_api/spec/spec.yml in this repository. The Apicurio project for the API is owned by Bilal Shaikh. Contact Bilal for priviledges to edit the project.
Please follow these steps to edit the specifications of the API:
- Login to Apicurio studio.
- Use Apicurio studio to edit the API as needed.
- Navigate to the Apicurio landing page page for the API.
- Click the '...' button at the top-right of the box for the API.
- Click the 'Download' menu option.
- Select 'Format' 'YAML'.
- Select 'References' 'Deference All External $refs'.
- Click the 'Download' button.
- Save the exported YAML file to
combine_api/spec/spec.ymlin this repository. - Commit the modified specifications file to this repository.
The API is implemented in Python using connexion. To edit the operation for a path, open the Python function for the path in your favorite Python editor and edit the function. The specifications of the API indicate the Python functions which handle each path (operationId of each HTTP method of each path). For example, the operationId for the /health path is combine_api.handlers.health.handler, which corresponds to the handler function in the combine_api.handlers.health Python module. connexion automatically maps each path to the functions indicated by the operationId attributes in the specifications of the API.
As described below, the COMBINE API is deployed as a Docker image. The Dockerfile for this image is the authoritative description of how to install and execute the API. The Dockerfile uses pipenv to install the required Python packages outlined in the Pipfile and Pipfile.lock files. Note, this Pipfile does not completely describe the requirements for the API. The Dockerfile includes additional operations which cannot be achieved using pipenv because some of the required Python packages for the API require additional OS packages and because bugs in pipenv currently prevent pipenv from installing one of the required Python packages for the API.
Below is an outline of how to install the API into a local Python environment managed with pipenv in a Linux machine.
- Change to this directory (
apps/combine-apisubdirectory of this repository). - Install the OS packages outlined in
Dockerfile:apt-get install default-jre perl r-base ...
- Use pipenv to create a Python environment with the required Python packages:
apt-get install python3 python3-pip pip3 install pipenv cd Dockerfile-assets pipenv install - Install the additional Python packages outlined at the end of the
Dockerfile(steps after thepipenv install ...step). These packages must be installed separately from pipenv because a bug in pipenv currently prevents pipenv from installing them.
- Follow the recommended installation steps above.
- Change to this directory (
apps/combine-apisubdirectory of this repository). - Use
aptor other methods to install any additional required OS packages. - Add these additional required OS packages to
Dockerfile. - Change to the directory for the Python environment for the API (
apps/combine-api/Dockerfile-assetssubdirectory of this repository). - Run
pipenv install ...to install any additional required Python packages. - Commit the modified
Dockerfile,Pipefile, andPipfile.lockfiles to this repository.
- Follow the recommended installation steps above.
- Change to the directory for the Python environment for the API (
apps/combine-api/Dockerfile-assetssubdirectory of this repository). - Activate this Python environment by running
pipenv shell. - Change to the root directory for this API by running (
cd ..). - Execute a server for the API by running
python -m combine_api. - Navigate your browser to the URL printed to your console (the default is currently http://0.0.0.0:3333/).
- Change to this directory (
apps/combine-apisubdirectory of this repository). - Run
docker build --tag ghcr.io/biosimulations/combine-api ..
As described below, Docker images for the API are available from the GitHub Container Registry (ghcr.io/biosimulations/combine-api). These images can be pulled by running docker pull ghcr.io/biosimulations/combine-api.
Follow these steps to run an image for the API:
- Execute the image on local port
3333by runningdocker run -it --rm -p 127.0.0.1:3333:3333 ghcr.io/biosimulations/combine-api. The second3333must match the port which the API is running at in the image (the default is currently3333). - Navigate your browser to
http://127.0.0.1:3333.
The combine-api in biosimulations uses a pyproject.toml file with Poetry as the primary
setup method. Please remember to clear your local poetry cache prior to installing the environment on your machine.
The API can be linted using flake8.
- Follow the recommended installation steps above.
- Change to the directory for the Python environment for the API (
apps/combine-api/Dockerfile-assetssubdirectory of this repository). - Activate this Python environment by running
pipenv shell. - Change to the root directory for this repository (
cd ../../..). - Run
flake8.
The CI system lints the API by running nx run combine-api:lint from the root directory of this repository.
The tests for the API are located in the tests subdirectory of this directory. The tests can be executed using pytest. Coverage can be accessed using pytest-cov.
- Follow the recommended installation steps above.
- Change to the directory for the Python environment for the API (
apps/combine-api/Dockerfile-assetssubdirectory of this repository). - Activate this Python environment by running
pipenv shell. - Change to the root directory for this API by running (
cd ..). - Run
python -m pytest tests/. a. To measure the coverage of the tests, add the--cov combine_apioption. b. To compile the coverage report to HTML, runcoverage html. c. To view the coverage report, navigate your browser to thehtmlcov/subdirectory of the directory for the Python environment for the API (apps/combine-api/Dockerfile-assets/htmlcov/index.html).
The CI system executes these tests by running nx run combine-api:test from the root directory of this repository.
The COMBINE API is deployed as a Docker image. Dockerfile is the Dockerfile for this image. This Dockerfile uses several files in the Dockerfile-assets subdirectory of this directory. This includes pipenv Pipfile and Pipfile.lock files which describe most of the Python packages required for the API. Note, this Pipfile does not completely describe the requirements for the API. The Dockerfile includes additional operations which cannot be achieved using pipenv because some of the required Python packages for the API require additional OS packages and because bugs in pipenv currently prevent pipenv from installing one of the required Python packages for the API.
The CI/CD system builds this image by running nx docker combine-api from the root directory of this repository and pushes it to the GitHub Container Registry.