Skip to content

Latest commit

 

History

History

submissions-api

Tree of Life Swagger OpenAPI 3 server

Overview

This Swagger API returns Tree of Life ToLIDs, taken from ToL sample naming project. Requests for new ToLIDs and prefixes can also be made.

This application uses the Connexion library on top of Flask.

This server was initially generated by the swagger-codegen project, using language "python-flask". You can easily generate a server stub by using the OpenAPI-Spec from a remote server.

Requirements

Python 3.5.2+

Setup

  • Set up a PostgreSQL/SQLlite database and set environment variable
export DB_URI=sqlite:///dev.db
  • Create a local Python virtual enviroment
python3 -m venv venv
  • Activate the Python virtual enviroment
source venv/bin/activate
  • Read and run the pre-reqs in setup.py
python3 setup.py install
  • Install all required Python libraries
pip3 install -r requirements.txt
  • Install connexion with extra install:
pip3 install 'connexion[swagger-ui]'
  • Insert users into the database (after starting the server so that the tables are built)
insert into user(user_id, name, api_key) values(100, 'Test User 1', 'b06810c5-2bdc-4faf-b5a9-4d3b52ed5fab');

Usage

To run the server:

source venv/bin/activate
python -m swagger_server

and open your browser to here:

http://localhost:8080/api/v2/ui/

You can directly test the server:

curl -X GET "http://localhost:8080/api/v2/tol-ids/search?taxonomyId=6344&specimenId=SAN0000100" -H  "accept: application/json"

The Swagger definition lives here:

http://localhost:8080/api/v2/openapi.json

To launch the integration tests, use tox:

sudo pip install tox
tox

Example usage and output

You can search for NCBI taxonomy ids in the "/public-name" end-point. You can also use CURL like this:

curl -X GET "http://localhost:8080/api/v2/tol-ids/search?taxonomyId=6344&specimenId=SAN0000100" -H  "accept: application/json"

The output for NCBI tax id 6344 will look something like this:

{
  "data": [
    {
      "class": "Polychaeta",
      "common_name": "lugworm",
      "family": "Arenicolidae",
      "genus": "Arenicola",
      "kingdom": "Metazoa",
      "order": "Capitellida",
      "phylum": "Annelida",
      "prefix": "wuAreMari",   
      "public_name": "wuAreMari1"
      "species": "Arenicola marina",
      "taxonomy_id": "6344"
    }
  ]
}

In the DToL manifest this maps to:

ORDER_OR_GROUP: Capitellida
FAMILY: Arenicolidae	
GENUS: Arenicola	
TAXON_ID: 6344	
SCIENTIFIC_NAME: Arenicola marina
COMMON_NAME: lugworm			

This is the URL from NCBI for id 6344