advanced.md
This file
Path
docs/advanced.md
43 lines · 991 bytes · Markdown
Last changed by
Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
History of this fileTake it
1234567891011121314151617181920212223242526272829303132333435363738394041424344# Advanced Usage
## Client Instances
Using a Client instance to make requests will give you HTTP connection pooling,will provide cookie persistence, and allows you to apply configuration acrossall outgoing requests.
```python>>> client = httpx.Client()>>> r = client.get('https://example.org/')>>> r<Response [200 OK]>```
## Calling into Python Web Apps
You can configure an `httpx` client to call directly into a Python webapplication, using either the WSGI or ASGI protocol.
This is particularly useful for two main use-cases:
* Using `httpx` as a client, inside test cases.* Mocking out external services, during tests or in dev/staging environments.
Here's an example of integrating against a Flask application:
```pythonfrom flask import Flaskimport httpx
app = Flask(__name__)
@app.route("/")def hello(): return "Hello World!"
client = httpx.Client(app=app)r = client.get('http://example/')assert r.status_code == 200assert r.text == "Hello World!"```