Skip to content
Myr

api.md

This file

Path

docs/api.md

153 lines · 5.2 KiB · Markdown

Last changed by

Force HTTP/1.1 on short-lived connections (#284)Seth Michael Larsonbefore adoptione7aa6d6

History of this file

Take it

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 1–2why, one step back
1# Developer Interface
2

Force HTTP/1.1 on short-lived connections (#284)Seth Michael Larsonbefore adoptione7aa6d6

line 3why, one step back
3## Helper Functions

http3 (#86)Tom Christiebefore adoptionc9747aa

line 4why, one step back
4

Force HTTP/1.1 on short-lived connections (#284)Seth Michael Larsonbefore adoptione7aa6d6

lines 5–10why, one step back
5!!! note
6 Only use these functions if you're testing HTTPX in a console7 or making a small number of requests. Using a `Client` will8 enable HTTP/2 and connection pooling for more efficient and9 long-lived connections.10

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 11–21why, one step back
11* `get(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`
12* `options(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`13* `head(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`14* `post(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`15* `put(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`16* `patch(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`17* `delete(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`18* `request(method, url, [data], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`1920## `Client`21

Force HTTP/1.1 on short-lived connections (#284)Seth Michael Larsonbefore adoptione7aa6d6

line 22why, one step back
22*An HTTP client, with connection pooling, HTTP/2, redirects, cookie persistence, etc.*

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 23–24why, one step back
23
24```python

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 25why, one step back
25>>> client = httpx.Client()

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 26–28why, one step back
26>>> response = client.get('https://example.org')
27```28

Allow setting headers at the Client level (#159)Stephen Brown IIbefore adoption72e6f47

line 29why, one step back
29* `def __init__([auth], [headers], [cookies], [verify], [cert], [timeout], [pool_limits], [max_redirects], [app], [dispatch])`

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 30–45why, one step back
30* `def .get(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`
31* `def .options(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`32* `def .head(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`33* `def .post(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`34* `def .put(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`35* `def .patch(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`36* `def .delete(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`37* `def .request(method, url, [data], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`38* `def .send(request, [stream], [allow_redirects], [verify], [cert], [timeout])`39* `def .close()`4041## `Response`4243*An HTTP response.*4445* `def __init__(...)`

Int status codes (#92)Tom Christiebefore adoption56a7943

line 46why, one step back
46* `.status_code` - **int**

http3 (#86)Tom Christiebefore adoptionc9747aa

line 47why, one step back
47* `.reason_phrase` - **str**

Response.protocol -> Response.http_version (#250)Tom Christiebefore adoptionc1ec1c3

line 48why, one step back
48* `.http_version` - `"HTTP/2"` or `"HTTP/1.1"`

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 49–71why, one step back
49* `.url` - **URL**
50* `.headers` - **Headers**51* `.content` - **bytes**52* `.text` - **str**53* `.encoding` - **str**54* `.is_redirect` - **bool**55* `.request` - **Request**56* `.cookies` - **Cookies**57* `.history` - **List[Response]**58* `def .raise_for_status()` - **None**59* `def .json()` - **Any**60* `def .read()` - **bytes**61* `def .stream()` - **bytes iterator**62* `def .raw()` - **bytes iterator**63* `def .close()` - **None**64* `def .next()` - **Response**6566## `Request`6768*An HTTP request. Can be constructed explicitly for more control over exactly69what gets sent over the wire.*7071```python

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 72why, one step back
72>>> request = httpx.Request("GET", "https://example.org", headers={'host': 'example.org'})

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 73–118why, one step back
73>>> response = client.send(request)
74```7576* `def __init__(method, url, [params], [data], [json], [headers], [cookies])`77* `.method` - **str**78* `.url` - **URL**79* `.content` - **byte** or **byte async iterator**80* `.headers` - **Headers**81* `.cookies` - **Cookies**8283## `URL`8485*A normalized, IDNA supporting URL.*8687```python88>>> url = URL("https://example.org/")89>>> url.host90'example.org'91```9293* `def __init__(url, allow_relative=False, params=None)`94* `.scheme` - **str**95* `.authority` - **str**96* `.host` - **str**97* `.port` - **int**98* `.path` - **str**99* `.query` - **str**100* `.full_path` - **str**101* `.fragment` - **str**102* `.is_ssl` - **bool**103* `.origin` - **Origin**104* `.is_absolute_url` - **bool**105* `.is_relative_url` - **bool**106* `def .copy_with([scheme], [authority], [path], [query], [fragment])` - **URL**107* `def .resolve_with(url)` - **URL**108109## `Origin`110111*A normalized, IDNA supporting set of scheme/host/port info.*112113```python114>>> Origin('https://example.org') == Origin('HTTPS://EXAMPLE.ORG:443')115True116```117118* `def __init__(url)`

Make Origin use scheme, not is_ssl (#168)Stephen Brown IIbefore adoption44beaa1

line 119why, one step back
119* `.scheme` - **str**

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 120–153why, one step back
120* `.is_ssl` - **bool**
121* `.host` - **str**122* `.port` - **int**123124## `Headers`125126*A case-insensitive multi-dict.*127128```python129>>> headers = Headers({'Content-Type': 'application/json'})130>>> headers['content-type']131'application/json'132```133134* `def __init__(self, headers)`135136## `Cookies`137138*A dict-like cookie store.*139140```python141>>> cookies = Cookies()142>>> cookies.set("name", "value", domain="example.org")143```144145* `def __init__(cookies: [dict, Cookies, CookieJar])`146* `.jar` - **CookieJar**147* `def extract_cookies(response)`148* `def set_cookie_header(request)`149* `def set(name, value, [domain], [path])`150* `def get(name, [domain], [path])`151* `def delete(name, [domain], [path])`152* `def clear([domain], [path])`153* *Standard mutable mapping interface*