Open
Description
it seems hyperlink
does not have a nice way to add path components to a base url, which is a very common operation when interacting with rest apis.
for example, consider
>>> from hyperlink import URL
>>> base_url = URL.from_text('https://example.org/api/v2')
let's assume i want to build a url for an endpoint below this base url, e.g. users/search
.
this works:
>>> base_url.replace(path=base_url.path + ('users', 'search'))
URL.from_text('https://example.org/api/v2/users/search')
... but let's face it, this is not so nice:
users/search
(likely copied from some documentation) needs manual splitting into a tuplebase_url
is referenced twice since the.path
tuple is required for the concatenation
making this nicer is not really possible with the current api. for example:
>>> base_url.replace(path=base_url.path + 'users/search'.split('/'))
[...]
TypeError: can only concatenate tuple (not "list") to tuple
oops. well, that's easy to work around:
>>> base_url.replace(path=base_url.path + tuple('users/search'.split('/')))
URL.from_text('https://example.org/api/v2/users/search')
...but the end result is even uglier.
it would be great if a use case like this is handled with a nicer api. thoughts?
Metadata
Metadata
Assignees
Labels
No labels