Skip to content
Myr

Document client-level configuration (#488)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Document client-level configuration * Fix typo

authored by Florimond Manca · committed by GitHub · parent 09db6ec · Browse files · 1 file+36 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+36 added−0 removed

  • other:+36 added−0 removed

1 file+36 added−0 removed

modified:docs/advanced.md+36 added
34 unmodified lines
35```3637Once you have a `Client`, you can use all the features documented in the [Quickstart](/quickstart) guide.3839### Configuration4041Clients allow you to apply configuration to all outgoing requests by passing parameters to the `Client` constructor.4243For example, to apply a set of custom headers on every request:4445```python46>>> url = 'http://httpbin.org/headers'47>>> headers = {'user-agent': 'my-app/0.0.1'}48>>> with httpx.Client(headers=headers) as client:49... r = client.get(url)50...51>>> r.json()['headers']['User-Agent']52'my-app/0.0.1'53```5455!!! note56 When you provide a parameter at both the client and request levels, one of two things can happen:57 58 - For headers, query parameters and cookies, the values are merged into one.59 - For all other parameters, the request-level value is used.6061Additionally, `Client` constructor accepts some parameters that aren't available at the request level.6263One particularly useful parameter is `base_url`, which allows you to define a base URL to prepend to all outgoing requests:6465```python66>>> with httpx.Client(base_url='http://httpbin.org') as client:67... r = client.get('/headers')68... 69>>> r.request.url70URL('http://httpbin.org/headers')71```7273For a list of all available client-level parameters, see the [`Client` API reference](/api/#client).7475## Calling into Python Web Apps7677You can configure an `httpx` client to call directly into a Python web78application using either the WSGI or ASGI protocol.
235 unmodified lines