advanced.md
This file
Path
docs/advanced.md
43 lines · 991 bytes · Markdown
Last changed by
Support WSGI and ASGI apps. (#94)Tom Christiebefore adoptionbb86970
History of this fileTake it
Support WSGI and ASGI apps. (#94)Tom Christiebefore adoptionbb86970
lines 1–43why, one step back1# Advanced Usage23## Client Instances45Using a Client instance to make requests will give you HTTP connection pooling,6will provide cookie persistence, and allows you to apply configuration across7all outgoing requests.89```python10>>> client = http3.Client()11>>> r = client.get('https://example.org/')12>>> r13<Response [200 OK]>14```1516## Calling into Python Web Apps1718You can configure an `http3` client to call directly into a Python web19application, using either the WSGI or ASGI protocol.2021This is particularly useful for two main use-cases:2223* Using `http3` as a client, inside test cases.24* Mocking out external services, during tests or in dev/staging environments.2526Here's an example of integrating against a Flask application:2728```python29from flask import Flask30import http3313233app = Flask(__name__)3435@app.route("/")36def hello():37 return "Hello World!"3839client = http3.Client(app=app)40r = client.get('http://example/')41assert r.status_code == 20042assert r.text == "Hello World!"43```