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

Allow defining a client-level base URL that is prepended to endpoint URLs in requests #83

Open
petebachant opened this issue May 27, 2022 · 2 comments

Comments

@petebachant
Copy link

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

I would like to make requests without the full URL.

Describe the solution you'd like

I'd like to define a class or instance attribute base_url that is automatically prepended to the endpoint passed into get, post, etc.

Describe alternatives you've considered
Considering subclassing, but it feels like this is a fundamental feature. Did I miss it in the documentation?

@holdenweb
Copy link

holdenweb commented Jun 15, 2022

You should look at the documentation for the @endpoint decorator - I'm afraid the README doesn't appear to honour fragments, so you'll want to do a text search on that page.

The decorator allows you to specify a base_url value that is prepended to all attributes, making it simple to relocate a set of endpoints into whatever web space you want to serve. The example in the docs is instructive but I won't repeat it here.

Please confirm this answer resolves your issue.

@petebachant
Copy link
Author

I took a look at the endpoint documentation, and it's not quite what I'm looking to do, since it looks like I would need to abstract all of my endpoints into a class, versus something simple like:

class MyClient(APIClient):
    base_url = "https://google.com"

c = MyClient()
something = c.get("/something")  # Automatically prepends base URL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants