How to query the API ?

With cURL

The REST API is queryable in command line by using cURL

Command :

$  curl --url 'https://metabocloud.mesocentre.uca.fr/index/compounds/HVYWMOMLDIMFJA-DPAQBDIFSA-N.png?community=chebi&size=medium&outputType=resource' \
        --output <path/to/output/file>

Output :

The PNG image is saved according to the path defined in the --output option.

With Python

One of the ways to query a REST-API with Python is to use the requests library.

After installing the requests library, you can query the REST API :

import requests

# Variables
file_format = "png"
output_type = "resource"
inchi_key = "Compound's InChI Key"
community = "Community from which the file must be retrieved"
size = "Image size wanted ('small', 'medium' or 'large')"

# Request
result = requests.get(f"https://metabocloud.mesocentre.uca.fr/index/compounds/{inchi_key}.{file_format}?community={community}&size={size}&outputType={output_type}")

# Metadata
headers = result.headers
metadata = dict(filter(lambda x: x[0].startswith("X-Metadata"), headers.items()))

# Output
with open("image.png", "wb") as file:
    file.write(result.content)

print("Metadata : ", metadata)

Output :

The PNG image is saved and the metadata are displayed.

Metadata :  {'X-Metadata-Chebi-Id': '16113', 'X-Metadata-Creation-Date': '2024-08-26', 'X-Metadata-Data-License': 'Creative Commons License (CC BY 4.0)', 'X-Metadata-Data-Source': 'Chemical Entities of Biological Interest (ChEBI) Database', 'X-Metadata-Image-Size': '350 x 350 px'}

Note

If you ran the application locally on your machine from a virtual environment or via Docker, you need to change the URL you send the request to. This means that https://metabocloud.mesocentre.uca.fr/index/compounds/ will become http://localhost:8084/compounds/ if you launched the application with the default parameters.

If you choose another port to run the application then you need to change the URL accordingly.

With a client generated by Swagger

From the OpenAPI specification file describing this REST API, you can auto-generated a client in the language you want thanks to Swagger using the option Generate Client in the menu.

The OpenAPI specification file is downloadable here : https://metabocloud.mesocentre.uca.fr/index/metabocloud-index.yaml