how to do request base_url without trailing slash? #3076
Replies: 5 comments 3 replies
-
What's wrong with async with httpx.AsyncClient(base_url='http://localhost:8000/api') as client:
response = await client.request('GET', 'books') |
Beta Was this translation helpful? Give feedback.
-
the same as with async with httpx.AsyncClient() as client:
response = await client.request('GET', 'http://localhost:8000/api/books') Under |
Beta Was this translation helpful? Give feedback.
-
Sorry, but it is a very bad solution, as client may be passed as argument to a service, that nothing knows about |
Beta Was this translation helpful? Give feedback.
-
I agree with @valq7711 and will expand on his/her comment. I am currently inheriting from The format is
instead of
due to the automatically added trailing slash. Upon passing the
as
The current state puts a rather strange restriction on what a base URL is supposed to be and breaks its reuse in case of only parameters being added (WCS example above). Not also that web browsers do not complain about double slash (at least not latest version of Chrome, Firefox and Edge), so if the base URL already has a trailing slash and the developer calls e.g. GET by adding more to the path, it will not cause issues. |
Beta Was this translation helpful? Give feedback.
-
I too find the behavior of always adding a slash to the end of the base URL a bit unexpected/undesirable. The explanatory comment in When building a client library using In general, I prefer libraries that let me decide the behavior I want and let me fail when I get it wrong. Or at least provide and escape hatch if the library is trying to be "smart" for me. To me, the behavior, logically, should be: url_to_calls = unmodified_provided_client_base_url + unmodified_provided_invoked_url
# examples
# "https://some.url.com/my/path" = "https://some.url.com" + "/my/path"
# "https://some.url.com/my/path" = "https://some.url.com/my" + "/path"
# "https://some.url.com/my/path" = "https://some.url.com/my/" + "path"
# "https://some.url.com/my//path" = "https://some.url.com/my/" + "/path"
# "https://some.url.com//my/path" = "https://some.url.com/" + "/my/path"
# "https://some.url.com/my/path" = "https://some.url.com/my/path" + "" Also it would be very nice if the url_to_calls = unmodified_provided_client_base_url + unmodified_provided_invoked_url if unmodified_provided_invoked_url is not None else "" |
Beta Was this translation helpful? Give feedback.
-
This example does request 'http://localhost:8000/api/books/', but I don't want trailing slash, how do I achieve that?
Note:
That's not the case described #2673, as final url is not empty.
The above issue is about joining - if nothing was passed => no join should be made.
Beta Was this translation helpful? Give feedback.
All reactions