MikeWooster / api-client

Separate the high level client implementation from the underlying CRUD.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

petebachant opened this issue · comments

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?

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.

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