Skip to content

Commit

Permalink
Replaces /reverse_lookup with a more sensible name.
Browse files Browse the repository at this point in the history
Closees #136.
  • Loading branch information
gaurav committed Oct 16, 2024
1 parent 9b18de1 commit a6c01a6
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions api/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,33 @@ class Request(BaseModel):
"""Reverse-lookup request body."""
curies: List[str]

class SynonymsRequest(BaseModel):
""" Synonyms search request body. """
preferred_curies: List[str]

@app.get(
"/reverse_lookup",
summary="Look up synonyms for a CURIE.",
description="Returns a list of synonyms for a particular CURIE.",
response_model=Dict[str, Dict],
tags=["lookup"],
deprecated=True,
)
@app.get(
"/synonyms",
summary="Look up synonyms for a CURIE.",
description="Returns a list of synonyms for a particular CURIE.",
response_model=Dict[str, Dict],
tags=["lookup"],
)
async def lookup_names_get(
curies: List[str]= Query(
preferred_curies: List[str]= Query(
example=["MONDO:0005737", "MONDO:0009757"],
description="A list of CURIEs to look up synonyms for."
)
) -> Dict[str, Dict]:
"""Returns a list of synonyms for a particular CURIE."""
return await reverse_lookup(curies)
return await reverse_lookup(preferred_curies)


@app.post(
Expand All @@ -124,16 +135,33 @@ async def lookup_names_get(
description="Returns a list of synonyms for a particular CURIE.",
response_model=Dict[str, Dict],
tags=["lookup"],
deprecated=True,
)
async def lookup_names_post(
request: Request = Body(..., example={
"curies": ["MONDO:0005737", "MONDO:0009757"],
}),
) -> Dict[str, List[str]]:
) -> Dict[str, Dict]:
"""Returns a list of synonyms for a particular CURIE."""
return await reverse_lookup(request.curies)


@app.post(
"/synonyms",
summary="Look up synonyms for a CURIE.",
description="Returns a list of synonyms for a particular CURIE.",
response_model=Dict[str, Dict],
tags=["lookup"],
)
async def lookup_names_post(
request: SynonymsRequest = Body(..., example={
"preferred_curies": ["MONDO:0005737", "MONDO:0009757"],
}),
) -> Dict[str, Dict]:
"""Returns a list of synonyms for a particular CURIE."""
return await reverse_lookup(request.preferred_curies)


async def reverse_lookup(curies) -> Dict[str, Dict]:
"""Returns a list of synonyms for a particular CURIE."""
query = f"http://{SOLR_HOST}:{SOLR_PORT}/solr/name_lookup/select"
Expand Down Expand Up @@ -492,5 +520,5 @@ async def lookup(string: str,
provider.add_span_processor(processor)
trace.set_tracer_provider(provider)
FastAPIInstrumentor.instrument_app(app, tracer_provider=provider, excluded_urls=
"docs,openapi.json")
"docs,openapi.json")
HTTPXClientInstrumentor().instrument()

0 comments on commit a6c01a6

Please sign in to comment.