Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Integrate LitVar into Seqvar page (#421) #509

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions backend/app/api/internal/endpoints/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,33 @@ async def pubtator3_api(request: Request, path: str):
headers=backend_resp.headers,
background=BackgroundTasks([BackgroundTask(backend_resp.aclose)]),
)


@router.get("/litvar/{path:path}")
async def litvar_api(request: Request, path: str):
"""
Proxy requests to the `LitVar <https://www.ncbi.nlm.nih.gov/research/bionlp/litvar/api/v1/entity/search>`_ backend.

:param request: request
:type request: :class:`fastapi.Request`
:param path: path to append to the backend URL
:type path: str
:return: response
:rtype: :class:`fastapi.responses.StreamingResponse`
"""
url = request.url
backend_url = "https://www.ncbi.nlm.nih.gov/research/bionlp/litvar/api/v1/entity/search/" + path

client = httpx_client_wrapper()
backend_req = client.build_request(
method=request.method,
url=backend_url,
content=await request.body(),
)
backend_resp = await client.send(backend_req, stream=True)
return StreamingResponse(
backend_resp.aiter_raw(),
status_code=backend_resp.status_code,
headers=backend_resp.headers,
background=BackgroundTasks([BackgroundTask(backend_resp.aclose)]),
)
16 changes: 16 additions & 0 deletions backend/tests/api/internal/test_remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,19 @@ async def test_pubtator3_api(httpx_mock: HTTPXMock, client: TestClient):
# assert:
assert response.status_code == 200
assert response.json() == {"res": "Mocked response"}


@pytest.mark.anyio
async def test_litvar_api(httpx_mock: HTTPXMock, client: TestClient):
"""Test forwarding to LitVar API."""
# arrange:
httpx_mock.add_response(
url="https://www.ncbi.nlm.nih.gov/research/bionlp/litvar/api/v1/entity/search/foo",
method="GET",
json={"res": "Mocked response"},
)
# act:
response = client.get("/internal/remote/litvar/foo")
# assert:
assert response.status_code == 200
assert response.json() == {"res": "Mocked response"}
1 change: 1 addition & 0 deletions frontend/src/plugins/reevFrontendLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export function setupBackendUrls() {
urlConfig.baseUrlViguno = '/internal/proxy/viguno'
urlConfig.baseUrlNginx = '/internal/proxy/nginx'
urlConfig.baseUrlPubtator = '/internal/remote/pubtator3-api'
urlConfig.baseUrlLitVar = '/internal/remote/litvar'
urlConfig.baseUrlCadaPrio = '/internal/proxy/cada-prio'
urlConfig.baseUrlDotty = '/internal/proxy/dotty'
urlConfig.baseUrlVariantValidator = '/internal/remote/variantvalidator'
Expand Down
Loading