question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Access /docs endpoint in FastAPI function apps

See original GitHub issue

When deploying FastAPI using the ASGI worker,

The /docs endpoint only seems to work for “anonymous” functions. Is there anything I can do to use it with authlevel “function”?

Question asked by @pietz

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Thyholtcommented, Oct 14, 2022

Thanks @pietz. Was able to make "try it out "work by including the code as a query argument in all the other endpoints as well. Didn’t put effort into reducing the repeated and unused code query argument, but it works. And the documentation tells the user to provide it. Example:

@app.get("/")
def root(code: str = Query(..., description="Azure Function App key")):
    return {"message": "Hello World"}
1reaction
pietzcommented, Sep 26, 2022

I found a workaround that at least brings me to the docs page. however, trying out the API doesn’t work this way for obvious reasons.

from fastapi.openapi.docs import get_swagger_ui_html

app = FastAPI(docs_url=None)

@app.get("/docs", include_in_schema=False)
async def get_docs(code: str):
    openapi_url = "/openapi.json?code=" + code
    return get_swagger_ui_html(openapi_url=openapi_url, title="docs")
Read more comments on GitHub >

github_iconTop Results From Across the Web

First Steps - FastAPI
First Steps¶ · Check it · Interactive API docs · Alternative API docs · OpenAPI · Step 1: import FastAPI · Step 2:...
Read more >
Documenting a FastAPI App with OpenAPI
This guide introduces how FastAPI creates documentation from your code. It also shows you how to provide custom information related to your API, ......
Read more >
Using FastAPI to Build Python Web APIs
The @app.get("/") tells FastAPI that the function right below is in charge of ... an alternative API documentation using ReDoc, which you can...
Read more >
Interactive API Docs - Feature of FastAPI
One of the major benefits of FastAPI is that it is fully compatible with open standards for APIs, OpenAPI and JSON Schema. It...
Read more >
FastAPI - Posit Connect: User Guide - Documentation
Endpoints in FastAPI are Python async functions, which allows multiple requests to be processed concurrently. This is useful when the response depends on ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found