Skip to content
Myr

Use a base_url in app dispatcher examples (#799)

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

authored by Florimond Manca · committed by GitHub · parent 82dc6f3 · Browse files · 2 files+6 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

2 files+6 added−6 removed

  • other:+6 added−6 removed

2 files+6 added−6 removed

modified:docs/advanced.md+3 added-3 removed
97 unmodified lines
98@app.route("/")99def hello():100 return "Hello World!"101102with httpx.Client(app=app) as client:103 r = client.get('http://example/')102with httpx.Client(app=app, base_url="http://testserver") as client:103 r = client.get("/")104 assert r.status_code == 200105 assert r.text == "Hello World!"106```107
7 unmodified lines
115116```python117# Instantiate a client that makes WSGI requests with a client IP of "1.2.3.4".118dispatch = httpx.WSGIDispatch(app=app, remote_addr="1.2.3.4")119with httpx.Client(dispatch=dispatch) as client:119with httpx.Client(dispatch=dispatch, base_url="http://testserver") as client:120 ...121```122123## Build Request
350 unmodified lines
modified:docs/async.md+3 added-3 removed
166 unmodified lines
167We can make requests directly against the application, like so:168169```python170>>> import httpx171>>> async with httpx.AsyncClient(app=app) as client:172... r = await client.get('http://example/')171>>> async with httpx.AsyncClient(app=app, base_url="http://testserver") as client:172... r = await client.get("/")173... assert r.status_code == 200174... assert r.text == "Hello World!"175```176
8 unmodified lines
185```python186# Instantiate a client that makes ASGI requests with a client IP of "1.2.3.4",187# on port 123.188dispatch = httpx.ASGIDispatch(app=app, client=("1.2.3.4", 123))189async with httpx.AsyncClient(dispatch=dispatch) as client:189async with httpx.AsyncClient(dispatch=dispatch, base_url="http://testserver") as client:190 ...191```192193See [the ASGI documentation](https://asgi.readthedocs.io/en/latest/specs/www.html#connection-scope) for more details on the `client` and `root_path` keys.
17 unmodified lines