Skip to content
Myr

api.md

This file

Path

docs/api.md

157 lines · 5.5 KiB · Markdown

Last changed by

Add `build_request` to `Client` (#319)Dobrovolsky Bogdanbefore adoption08edfac

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–18why, 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])`

Add `build_request` to `Client` (#319)Dobrovolsky Bogdanbefore adoption08edfac

line 19why, one step back
19* `build_request(method, url, [data], [files], [json], [params], [headers], [cookies])`

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 20–22why, one step back
20
21## `Client`22

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

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

http3 (#86)Tom Christiebefore adoptionc9747aa

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

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

http3 (#86)Tom Christiebefore adoptionc9747aa

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

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

line 30why, one step back
30* `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 31–32why, one step back
31* `.headers` - **Headers**
32* `.cookies` - **Cookies**

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 33–40why, one step back
33* `def .get(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`
34* `def .options(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`35* `def .head(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`36* `def .post(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`37* `def .put(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`38* `def .patch(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`39* `def .delete(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`40* `def .request(method, url, [data], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`

Add `build_request` to `Client` (#319)Dobrovolsky Bogdanbefore adoption08edfac

line 41why, one step back
41* `def .build_request(method, url, [data], [files], [json], [params], [headers], [cookies])`

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 42–49why, one step back
42* `def .send(request, [stream], [allow_redirects], [verify], [cert], [timeout])`
43* `def .close()`4445## `Response`4647*An HTTP response.*4849* `def __init__(...)`

Int status codes (#92)Tom Christiebefore adoption56a7943

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

http3 (#86)Tom Christiebefore adoptionc9747aa

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

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

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

http3 (#86)Tom Christiebefore adoptionc9747aa

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

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 77–122why, one step back
77>>> response = client.send(request)
78```7980* `def __init__(method, url, [params], [data], [json], [headers], [cookies])`81* `.method` - **str**82* `.url` - **URL**83* `.content` - **byte** or **byte async iterator**84* `.headers` - **Headers**85* `.cookies` - **Cookies**8687## `URL`8889*A normalized, IDNA supporting URL.*9091```python92>>> url = URL("https://example.org/")93>>> url.host94'example.org'95```9697* `def __init__(url, allow_relative=False, params=None)`98* `.scheme` - **str**99* `.authority` - **str**100* `.host` - **str**101* `.port` - **int**102* `.path` - **str**103* `.query` - **str**104* `.full_path` - **str**105* `.fragment` - **str**106* `.is_ssl` - **bool**107* `.origin` - **Origin**108* `.is_absolute_url` - **bool**109* `.is_relative_url` - **bool**110* `def .copy_with([scheme], [authority], [path], [query], [fragment])` - **URL**111* `def .resolve_with(url)` - **URL**112113## `Origin`114115*A normalized, IDNA supporting set of scheme/host/port info.*116117```python118>>> Origin('https://example.org') == Origin('HTTPS://EXAMPLE.ORG:443')119True120```121122* `def __init__(url)`

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

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

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 124–157why, one step back
124* `.is_ssl` - **bool**
125* `.host` - **str**126* `.port` - **int**127128## `Headers`129130*A case-insensitive multi-dict.*131132```python133>>> headers = Headers({'Content-Type': 'application/json'})134>>> headers['content-type']135'application/json'136```137138* `def __init__(self, headers)`139140## `Cookies`141142*A dict-like cookie store.*143144```python145>>> cookies = Cookies()146>>> cookies.set("name", "value", domain="example.org")147```148149* `def __init__(cookies: [dict, Cookies, CookieJar])`150* `.jar` - **CookieJar**151* `def extract_cookies(response)`152* `def set_cookie_header(request)`153* `def set(name, value, [domain], [path])`154* `def get(name, [domain], [path])`155* `def delete(name, [domain], [path])`156* `def clear([domain], [path])`157* *Standard mutable mapping interface*