Skip to content
Myr

api.md

This file

Path

docs/api.md

155 lines · 5.3 KiB · Markdown

Last changed by

Automatically convert Client.cookies and Client.headers on set (#274)toppkbefore adoption9e420a5

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])`

Automatically convert Client.cookies and Client.headers on set (#274)toppkbefore adoption9e420a5

lines 30–31why, one step back
30* `.headers` - **Headers**
31* `.cookies` - **Cookies**

http3 (#86)Tom Christiebefore adoptionc9747aa

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

Int status codes (#92)Tom Christiebefore adoption56a7943

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

http3 (#86)Tom Christiebefore adoptionc9747aa

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

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

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

http3 (#86)Tom Christiebefore adoptionc9747aa

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

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 75–120why, one step back
75>>> response = client.send(request)
76```7778* `def __init__(method, url, [params], [data], [json], [headers], [cookies])`79* `.method` - **str**80* `.url` - **URL**81* `.content` - **byte** or **byte async iterator**82* `.headers` - **Headers**83* `.cookies` - **Cookies**8485## `URL`8687*A normalized, IDNA supporting URL.*8889```python90>>> url = URL("https://example.org/")91>>> url.host92'example.org'93```9495* `def __init__(url, allow_relative=False, params=None)`96* `.scheme` - **str**97* `.authority` - **str**98* `.host` - **str**99* `.port` - **int**100* `.path` - **str**101* `.query` - **str**102* `.full_path` - **str**103* `.fragment` - **str**104* `.is_ssl` - **bool**105* `.origin` - **Origin**106* `.is_absolute_url` - **bool**107* `.is_relative_url` - **bool**108* `def .copy_with([scheme], [authority], [path], [query], [fragment])` - **URL**109* `def .resolve_with(url)` - **URL**110111## `Origin`112113*A normalized, IDNA supporting set of scheme/host/port info.*114115```python116>>> Origin('https://example.org') == Origin('HTTPS://EXAMPLE.ORG:443')117True118```119120* `def __init__(url)`

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

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

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 122–155why, one step back
122* `.is_ssl` - **bool**
123* `.host` - **str**124* `.port` - **int**125126## `Headers`127128*A case-insensitive multi-dict.*129130```python131>>> headers = Headers({'Content-Type': 'application/json'})132>>> headers['content-type']133'application/json'134```135136* `def __init__(self, headers)`137138## `Cookies`139140*A dict-like cookie store.*141142```python143>>> cookies = Cookies()144>>> cookies.set("name", "value", domain="example.org")145```146147* `def __init__(cookies: [dict, Cookies, CookieJar])`148* `.jar` - **CookieJar**149* `def extract_cookies(response)`150* `def set_cookie_header(request)`151* `def set(name, value, [domain], [path])`152* `def get(name, [domain], [path])`153* `def delete(name, [domain], [path])`154* `def clear([domain], [path])`155* *Standard mutable mapping interface*