api.md
This file
Path
docs/api.md
163 lines · 6.1 KiB · Markdown
Last changed by
Document client block-usage and close() (#487)Florimond Mancabefore adoption074cd25
History of this fileTake it
The walk stopped after 200 commits: lines older than 87e199e point at it.
Tweak READMETom Christiebefore adoption87e199e
lines 1–2why, one step back1# Developer Interface2Force HTTP/1.1 on short-lived connections (#284)Seth Michael Larsonbefore adoptione7aa6d6
line 3why, one step back3## Helper FunctionsTweak READMETom Christiebefore adoption87e199e
line 4why, one step back4Force HTTP/1.1 on short-lived connections (#284)Seth Michael Larsonbefore adoptione7aa6d6
lines 5–10why, one step back5!!! note6 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.10Configure Proxy from Client (#353)Seth Michael Larsonbefore adoptionb0fa085
lines 11–13why, one step back11* `get(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`12* `options(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`13* `head(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`Document the files parameter on .post(), .patch(), and .put() (#409) (#414)Davit Tovmasyanbefore adoption2f2a4e4
lines 14–16why, one step back14* `post(url, [data], [files], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`15* `put(url, [data], [files], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`16* `patch(url, [data], [files], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`Remove data, json and files parameters in delete() function (#408)Jt Miclatbefore adoption6752f7d
line 17why, one step back17* `delete(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`Document the files parameter on .post(), .patch(), and .put() (#409) (#414)Davit Tovmasyanbefore adoption2f2a4e4
line 18why, one step back18* `request(method, url, [data], [files], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`Add `build_request` to `Client` (#319)Dobrovolsky Bogdanbefore adoption08edfac
line 19why, one step back19* `build_request(method, url, [data], [files], [json], [params], [headers], [cookies])`Tweak READMETom Christiebefore adoption87e199e
lines 20–22why, one step back2021## `Client`22Force HTTP/1.1 on short-lived connections (#284)Seth Michael Larsonbefore adoptione7aa6d6
line 23why, one step back23*An HTTP client, with connection pooling, HTTP/2, redirects, cookie persistence, etc.*Tweak READMETom Christiebefore adoption87e199e
lines 24–25why, one step back2425```pythonDocument client block-usage and close() (#487)Florimond Mancabefore adoption074cd25
lines 26–27why, one step back26>>> with httpx.Client() as client:27... response = client.get('https://example.org')Tweak READMETom Christiebefore adoption87e199e
lines 28–29why, one step back28```29Adding params to Client (#372)Tyrel Souzabefore adoption5dc646f
lines 30–31why, one step back30* `def __init__([auth], [params], [headers], [cookies], [verify], [cert], [timeout], [pool_limits], [max_redirects], [app], [dispatch])`31* `.params` - **QueryParams**Automatically convert Client.cookies and Client.headers on set (#274)toppkbefore adoption9e420a5
lines 32–33why, one step back32* `.headers` - **Headers**33* `.cookies` - **Cookies**Configure Proxy from Client (#353)Seth Michael Larsonbefore adoptionb0fa085
lines 34–36why, one step back34* `def .get(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`35* `def .options(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`36* `def .head(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`Document the files parameter on .post(), .patch(), and .put() (#409) (#414)Davit Tovmasyanbefore adoption2f2a4e4
lines 37–39why, one step back37* `def .post(url, [data], [files], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`38* `def .put(url, [data], [files], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`39* `def .patch(url, [data], [files], [json], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`Remove data, json and files parameters in delete() function (#408)Jt Miclatbefore adoption6752f7d
line 40why, one step back40* `def .delete(url, [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`Document the files parameter on .post(), .patch(), and .put() (#409) (#414)Davit Tovmasyanbefore adoption2f2a4e4
line 41why, one step back41* `def .request(method, url, [data], [files], [params], [headers], [cookies], [auth], [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`Add `build_request` to `Client` (#319)Dobrovolsky Bogdanbefore adoption08edfac
line 42why, one step back42* `def .build_request(method, url, [data], [files], [json], [params], [headers], [cookies])`Configure Proxy from Client (#353)Seth Michael Larsonbefore adoptionb0fa085
line 43why, one step back43* `def .send(request, [stream], [allow_redirects], [verify], [cert], [timeout], [proxies])`Tweak READMETom Christiebefore adoption87e199e
lines 44–52why, one step back44* `def .close()`4546## `Response`4748*An HTTP response.*4950* `def __init__(...)`51* `.status_code` - **int**52* `.reason_phrase` - **str**Response.protocol -> Response.http_version (#250)Tom Christiebefore adoptionc1ec1c3
line 53why, one step back53* `.http_version` - `"HTTP/2"` or `"HTTP/1.1"`Tweak READMETom Christiebefore adoption87e199e
lines 54–62why, one step back54* `.url` - **URL**55* `.headers` - **Headers**56* `.content` - **bytes**57* `.text` - **str**58* `.encoding` - **str**59* `.is_redirect` - **bool**60* `.request` - **Request**61* `.cookies` - **Cookies**62* `.history` - **List[Response]**Add `.elapsed` onto Response objects tracking how long a request took. (#351)Roy Williamsbefore adoption05ac117
lines 63–67why, one step back63* `.elapsed` - **[timedelta](https://docs.python.org/3/library/datetime.html)**64 * The amount of time elapsed between sending the first byte and parsing the headers (not including time spent reading65 the response). Use66 [total_seconds()](https://docs.python.org/3/library/datetime.html#datetime.timedelta.total_seconds) to correctly get67 the total elapsed seconds.Tweak READMETom Christiebefore adoption87e199e
lines 68–81why, one step back68* `def .raise_for_status()` - **None**69* `def .json()` - **Any**70* `def .read()` - **bytes**71* `def .stream()` - **bytes iterator**72* `def .raw()` - **bytes iterator**73* `def .close()` - **None**74* `def .next()` - **Response**7576## `Request`7778*An HTTP request. Can be constructed explicitly for more control over exactly79what gets sent over the wire.*8081```pythonRenaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 82why, one step back82>>> request = httpx.Request("GET", "https://example.org", headers={'host': 'example.org'})Tweak READMETom Christiebefore adoption87e199e
lines 83–128why, one step back83>>> response = client.send(request)84```8586* `def __init__(method, url, [params], [data], [json], [headers], [cookies])`87* `.method` - **str**88* `.url` - **URL**89* `.content` - **byte** or **byte async iterator**90* `.headers` - **Headers**91* `.cookies` - **Cookies**9293## `URL`9495*A normalized, IDNA supporting URL.*9697```python98>>> url = URL("https://example.org/")99>>> url.host100'example.org'101```102103* `def __init__(url, allow_relative=False, params=None)`104* `.scheme` - **str**105* `.authority` - **str**106* `.host` - **str**107* `.port` - **int**108* `.path` - **str**109* `.query` - **str**110* `.full_path` - **str**111* `.fragment` - **str**112* `.is_ssl` - **bool**113* `.origin` - **Origin**114* `.is_absolute_url` - **bool**115* `.is_relative_url` - **bool**116* `def .copy_with([scheme], [authority], [path], [query], [fragment])` - **URL**117* `def .resolve_with(url)` - **URL**118119## `Origin`120121*A normalized, IDNA supporting set of scheme/host/port info.*122123```python124>>> Origin('https://example.org') == Origin('HTTPS://EXAMPLE.ORG:443')125True126```127128* `def __init__(url)`Make Origin use scheme, not is_ssl (#168)Stephen Brown IIbefore adoption44beaa1
line 129why, one step back129* `.scheme` - **str**Tweak READMETom Christiebefore adoption87e199e
lines 130–163why, one step back130* `.is_ssl` - **bool**131* `.host` - **str**132* `.port` - **int**133134## `Headers`135136*A case-insensitive multi-dict.*137138```python139>>> headers = Headers({'Content-Type': 'application/json'})140>>> headers['content-type']141'application/json'142```143144* `def __init__(self, headers)`145146## `Cookies`147148*A dict-like cookie store.*149150```python151>>> cookies = Cookies()152>>> cookies.set("name", "value", domain="example.org")153```154155* `def __init__(cookies: [dict, Cookies, CookieJar])`156* `.jar` - **CookieJar**157* `def extract_cookies(response)`158* `def set_cookie_header(request)`159* `def set(name, value, [domain], [path])`160* `def get(name, [domain], [path])`161* `def delete(name, [domain], [path])`162* `def clear([domain], [path])`163* *Standard mutable mapping interface*