[FEATURE] Easy way to enable/disable endpoint

See original GitHub issue

Is your feature request related to a problem? Please describe.

This is not a problem but rather something that occurs quite commonly. Sometimes you just want to expose a certain endpoint based on configuration settings or environment. Currently there is include_in_schema flag that hides the endpoint in OpenAPI schema but the actual endpoint is still present and responsive. There should be a way to disable endpoint entirely from being exposed.

Describe the solution you’d like

I think there should be a disabled or enabled flag on APIRoute.api_route method to easily enable the endpoint and not exposing it at all.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
dmontagucommented, Sep 20, 2019

@LKay If you want to exclude based on a boolean flag, is there a reason you couldn’t just put the route definition inside a conditional block, conditioning on the condition you’d pass as enabled or disabled anyway? It seems to me even if the flag you are requesting was added, the following would be equivalent:

if not exclude_condition:
    @app.get("/excluded")
    async def excluded_list():
        return {"excluded": True}
@app.get("/excluded", disabled=exclude_condition)
async def excluded_list():
    return {"excluded": True}

The benefit to the first approach would be that it wouldn’t require a new keyword argument on all of the route decorators (and there are already so many!).

Is there something this approach wouldn’t handle?

1reaction
LKaycommented, Nov 27, 2019

Handled using wrapping if statements around routes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Enable and disable endpoints at runtime with Spring boot
You can either use @ConditionalOnExpression or @ConditionalOnProperty @RestController @ConditionalOnExpression("${my.property:false}") ...
Read more >
How to disable or enable the REST API endpoint in Yoast SEO
1. When you're logged in, you will be in your 'Dashboard'. 2. On the left-hand side, you will see a menu. In that...
Read more >
Disable API Gateway default endpoint API - Amazon AWS
Open the API Gateway console. · In the navigation pane, choose APIs, and then choose your REST API. · In the navigation pane,...
Read more >
Manage network policies for private endpoints - Microsoft Learn
Disable network policy · Sign-in to the Azure portal. · In the search box at the top of the portal, enter Virtual network....
Read more >
Enabling and Disabling Services - Google Cloud
For most operational use cases, the simplest way to enable and disable services is to use Google Cloud console. If you need to...
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