Skip to content
Myr

Link to ASGI docs (#577)

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

authored by Tom Christie · committed by GitHub · parent 248aa58 · Browse files · 1 file+9 added−6 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+9 added−6 removed

  • other:+9 added−6 removed

1 file+9 added−6 removed

modified:docs/advanced.md+9 added-6 removed
73 unmodified lines
7475## Calling into Python Web Apps7677You can configure an `httpx` client to call directly into a Python web78application using either the ASGI protocol.78application using the ASGI protocol.7980This is particularly useful for two main use-cases:8182* Using `httpx` as a client inside test cases.
23 unmodified lines
106... assert r.status_code == 200107... assert r.text == "Hello World!"108```109110For some more complex cases you might need to customize the WSGI or ASGI111dispatch. This allows you to:110For some more complex cases you might need to customise the ASGI dispatch. This allows you to:111112* Inspect 500 error responses rather than raise exceptions by setting `raise_app_exceptions=False`.114* Mount the WSGI or ASGI application at a subpath by setting `root_path`.113* Mount the ASGI application at a subpath by setting `root_path`.114* Use a given client address for requests by setting `client`.115116For example:117118```python120# Instantiate a client that makes WSGI requests with a client IP of "1.2.3.4".121dispatch = httpx.dispatch.ASGIDispatch(app=app, remote_addr="1.2.3.4")119# Instantiate a client that makes ASGI requests with a client IP of "1.2.3.4",120# on port 123.121dispatch = httpx.dispatch.ASGIDispatch(app=app, client=("1.2.3.4", 123))122async with httpx.Client(dispatch=dispatch) as client:123 ...124```125126See [the ASGI documentation](https://asgi.readthedocs.io/en/latest/specs/www.html#connection-scope) for more details on the `client` and `root_path`127keys.128129## Build Request130131You can use `Client.build_request()` to build a request and132make modifications before sending the request.
316 unmodified lines