api.md
This file
Path
docs/api.md
158 lines · 3.6 KiB · Markdown
Last changed by
Drop sync (#544)Tom Christiebefore adoption206c537
History of this fileTake it
The walk stopped after 200 commits: lines older than 7ff8483 point at it.
Version 0.6.1Tom Christiebefore adoption7ff8483
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 FunctionsVersion 0.6.1Tom Christiebefore adoption7ff8483
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.10First pass at autodoc support (#464)Tom Christiebefore adoption1ce3cc3
lines 11–12why, one step back11::: httpx.request12 :docstring:Version 0.6.1Tom Christiebefore adoption7ff8483
line 13why, one step back13First pass at autodoc support (#464)Tom Christiebefore adoption1ce3cc3
lines 14–15why, one step back14::: httpx.get15 :docstring:Version 0.6.1Tom Christiebefore adoption7ff8483
line 16why, one step back16First pass at autodoc support (#464)Tom Christiebefore adoption1ce3cc3
lines 17–18why, one step back17::: httpx.options18 :docstring:Version 0.6.1Tom Christiebefore adoption7ff8483
line 19why, one step back19First pass at autodoc support (#464)Tom Christiebefore adoption1ce3cc3
lines 20–21why, one step back20::: httpx.head21 :docstring:Version 0.6.1Tom Christiebefore adoption7ff8483
line 22why, one step back22First pass at autodoc support (#464)Tom Christiebefore adoption1ce3cc3
lines 23–38why, one step back23::: httpx.post24 :docstring:2526::: httpx.put27 :docstring:2829::: httpx.patch30 :docstring:3132::: httpx.delete33 :docstring:3435## `Client`3637::: httpx.Client38 :docstring:Drop sync (#544)Tom Christiebefore adoption206c537
line 39why, one step back39 :members: headers cookies params request get head options post put patch delete build_request send closeVersion 0.6.1Tom Christiebefore adoption7ff8483
lines 40–47why, one step back4041## `Response`4243*An HTTP response.*4445* `def __init__(...)`46* `.status_code` - **int**47* `.reason_phrase` - **str**Response.protocol -> Response.http_version (#250)Tom Christiebefore adoptionc1ec1c3
line 48why, one step back48* `.http_version` - `"HTTP/2"` or `"HTTP/1.1"`Version 0.6.1Tom Christiebefore adoption7ff8483
lines 49–57why, one step back49* `.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]**Add `.elapsed` onto Response objects tracking how long a request took. (#351)Roy Williamsbefore adoption05ac117
lines 58–62why, one step back58* `.elapsed` - **[timedelta](https://docs.python.org/3/library/datetime.html)**59 * The amount of time elapsed between sending the first byte and parsing the headers (not including time spent reading60 the response). Use61 [total_seconds()](https://docs.python.org/3/library/datetime.html#datetime.timedelta.total_seconds) to correctly get62 the total elapsed seconds.Version 0.6.1Tom Christiebefore adoption7ff8483
lines 63–76why, one step back63* `def .raise_for_status()` - **None**64* `def .json()` - **Any**65* `def .read()` - **bytes**66* `def .stream()` - **bytes iterator**67* `def .raw()` - **bytes iterator**68* `def .close()` - **None**69* `def .next()` - **Response**7071## `Request`7273*An HTTP request. Can be constructed explicitly for more control over exactly74what gets sent over the wire.*7576```pythonRenaming -> httpx (#129)Tom Christiebefore adoption2d09d5b
line 77why, one step back77>>> request = httpx.Request("GET", "https://example.org", headers={'host': 'example.org'})Drop sync (#544)Tom Christiebefore adoption206c537
line 78why, one step back78>>> response = await client.send(request)Version 0.6.1Tom Christiebefore adoption7ff8483
lines 79–123why, one step back79```8081* `def __init__(method, url, [params], [data], [json], [headers], [cookies])`82* `.method` - **str**83* `.url` - **URL**84* `.content` - **byte** or **byte async iterator**85* `.headers` - **Headers**86* `.cookies` - **Cookies**8788## `URL`8990*A normalized, IDNA supporting URL.*9192```python93>>> url = URL("https://example.org/")94>>> url.host95'example.org'96```9798* `def __init__(url, allow_relative=False, params=None)`99* `.scheme` - **str**100* `.authority` - **str**101* `.host` - **str**102* `.port` - **int**103* `.path` - **str**104* `.query` - **str**105* `.full_path` - **str**106* `.fragment` - **str**107* `.is_ssl` - **bool**108* `.origin` - **Origin**109* `.is_absolute_url` - **bool**110* `.is_relative_url` - **bool**111* `def .copy_with([scheme], [authority], [path], [query], [fragment])` - **URL**112* `def .resolve_with(url)` - **URL**113114## `Origin`115116*A normalized, IDNA supporting set of scheme/host/port info.*117118```python119>>> Origin('https://example.org') == Origin('HTTPS://EXAMPLE.ORG:443')120True121```122123* `def __init__(url)`Make Origin use scheme, not is_ssl (#168)Stephen Brown IIbefore adoption44beaa1
line 124why, one step back124* `.scheme` - **str**Version 0.6.1Tom Christiebefore adoption7ff8483
lines 125–158why, one step back125* `.is_ssl` - **bool**126* `.host` - **str**127* `.port` - **int**128129## `Headers`130131*A case-insensitive multi-dict.*132133```python134>>> headers = Headers({'Content-Type': 'application/json'})135>>> headers['content-type']136'application/json'137```138139* `def __init__(self, headers)`140141## `Cookies`142143*A dict-like cookie store.*144145```python146>>> cookies = Cookies()147>>> cookies.set("name", "value", domain="example.org")148```149150* `def __init__(cookies: [dict, Cookies, CookieJar])`151* `.jar` - **CookieJar**152* `def extract_cookies(response)`153* `def set_cookie_header(request)`154* `def set(name, value, [domain], [path])`155* `def get(name, [domain], [path])`156* `def delete(name, [domain], [path])`157* `def clear([domain], [path])`158* *Standard mutable mapping interface*