Skip to content

Commit 7241535

Browse files
author
Can Sarigol
committed
Added doc for base_url's subpaths samples.
1 parent 9a5c866 commit 7241535

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

docs/advanced.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,22 @@ For example, `base_url` allows you to prepend an URL to all outgoing requests:
143143
URL('http://httpbin.org/headers')
144144
```
145145

146+
`base_url` also accepts URLs with subpaths. In the following code examples, `r.request.url` gives the same result for `base_url` with a slash and no slash character:
147+
148+
```python
149+
>>> with httpx.Client(base_url='http://httpbin.org/v1') as client:
150+
... r = client.get('/headers')
151+
...
152+
>>> r.request.url
153+
URL('http://httpbin.org/v1/headers')
154+
155+
>>> with httpx.Client(base_url='http://httpbin.org/v1/') as client:
156+
... r = client.get('/headers')
157+
...
158+
>>> r.request.url
159+
URL('http://httpbin.org/v1/headers')
160+
```
161+
146162
For a list of all available client parameters, see the [`Client`](/api/#client) API reference.
147163

148164
## Calling into Python Web Apps

0 commit comments

Comments
 (0)