Skip to content
Myr

api.md

This file

Path

docs/api.md

147 lines · 5.0 KiB · Markdown

Last changed by

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

History of this file

Take it

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 1–18why, one step back
1# Developer Interface
23## Main Interface45* `get(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`6* `options(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`7* `head(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`8* `post(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`9* `put(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`10* `patch(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`11* `delete(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`12* `request(method, url, [data], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`1314## `Client`1516*An HTTP client, with connection pooling, redirects, cookie persistence, etc.*1718```python

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 20–22why, one step back
20>>> response = client.get('https://example.org')
21```22

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

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

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 24–39why, one step back
24* `def .get(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`
25* `def .options(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`26* `def .head(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`27* `def .post(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`28* `def .put(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`29* `def .patch(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`30* `def .delete(url, [data], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`31* `def .request(method, url, [data], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout])`32* `def .send(request, [stream], [allow_redirects], [verify], [cert], [timeout])`33* `def .close()`3435## `Response`3637*An HTTP response.*3839* `def __init__(...)`

Int status codes (#92)Tom Christiebefore adoption56a7943

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

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 41–65why, one step back
41* `.reason_phrase` - **str**
42* `.protocol` - `"HTTP/2"` or `"HTTP/1.1"`43* `.url` - **URL**44* `.headers` - **Headers**45* `.content` - **bytes**46* `.text` - **str**47* `.encoding` - **str**48* `.is_redirect` - **bool**49* `.request` - **Request**50* `.cookies` - **Cookies**51* `.history` - **List[Response]**52* `def .raise_for_status()` - **None**53* `def .json()` - **Any**54* `def .read()` - **bytes**55* `def .stream()` - **bytes iterator**56* `def .raw()` - **bytes iterator**57* `def .close()` - **None**58* `def .next()` - **Response**5960## `Request`6162*An HTTP request. Can be constructed explicitly for more control over exactly63what gets sent over the wire.*6465```python

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

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

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 67–112why, one step back
67>>> response = client.send(request)
68```6970* `def __init__(method, url, [params], [data], [json], [headers], [cookies])`71* `.method` - **str**72* `.url` - **URL**73* `.content` - **byte** or **byte async iterator**74* `.headers` - **Headers**75* `.cookies` - **Cookies**7677## `URL`7879*A normalized, IDNA supporting URL.*8081```python82>>> url = URL("https://example.org/")83>>> url.host84'example.org'85```8687* `def __init__(url, allow_relative=False, params=None)`88* `.scheme` - **str**89* `.authority` - **str**90* `.host` - **str**91* `.port` - **int**92* `.path` - **str**93* `.query` - **str**94* `.full_path` - **str**95* `.fragment` - **str**96* `.is_ssl` - **bool**97* `.origin` - **Origin**98* `.is_absolute_url` - **bool**99* `.is_relative_url` - **bool**100* `def .copy_with([scheme], [authority], [path], [query], [fragment])` - **URL**101* `def .resolve_with(url)` - **URL**102103## `Origin`104105*A normalized, IDNA supporting set of scheme/host/port info.*106107```python108>>> Origin('https://example.org') == Origin('HTTPS://EXAMPLE.ORG:443')109True110```111112* `def __init__(url)`

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

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

http3 (#86)Tom Christiebefore adoptionc9747aa

lines 114–147why, one step back
114* `.is_ssl` - **bool**
115* `.host` - **str**116* `.port` - **int**117118## `Headers`119120*A case-insensitive multi-dict.*121122```python123>>> headers = Headers({'Content-Type': 'application/json'})124>>> headers['content-type']125'application/json'126```127128* `def __init__(self, headers)`129130## `Cookies`131132*A dict-like cookie store.*133134```python135>>> cookies = Cookies()136>>> cookies.set("name", "value", domain="example.org")137```138139* `def __init__(cookies: [dict, Cookies, CookieJar])`140* `.jar` - **CookieJar**141* `def extract_cookies(response)`142* `def set_cookie_header(request)`143* `def set(name, value, [domain], [path])`144* `def get(name, [domain], [path])`145* `def delete(name, [domain], [path])`146* `def clear([domain], [path])`147* *Standard mutable mapping interface*