get_fastapi_router

get_fastapi_router(converter: Converter, **kwargs: Any) fastapi.APIRouter[source]

Get a router for fastapi.FastAPI.

Parameters:
  • converter – A converter

  • kwargs – Keyword arguments passed through to fastapi.APIRouter

Returns:

A router

The following is an end-to-end example of using this function to create a small web resolver application.

Create a python file with your fastapi.FastAPI instance:

# fastapi_example.py
from fastapi import FastAPI
from curies import Converter, get_fastapi_router

# Create a converter
converter = Converter.get_obo_converter()

# Create a router from the converter
router = get_fastapi_router(converter)

# Create the FastAPI and mount the router
app = FastAPI()
app.include_router(router)

In the command line,, run your Python file with uvicorn:

$ pip install uvicorn
$ uvicorn fastapi_example:app --port 8764 --host 0.0.0.0

Test a request in the Python REPL.

import requests

url = requests.get("http://localhost:8764/GO:0032571").url
assert url == "http://amigo.geneontology.org/amigo/term/GO:0032571"