api.md
This file
Path
docs/api.md
159 lines · 3.8 KiB · Markdown
Last changed by
response.elapsed now reflects entire request/response time. (#692)Tom Christiebefore adoption6a1ee0e
History of this fileTake it
The walk stopped after 200 commits: lines older than 0c4460e point at it.
Add example of specifying HTTP versions (#337)Paul (xobb) Chubatyybefore adoption0c4460e
lines 1–10why, one step back1# Developer Interface23## Helper Functions45!!! 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:Add example of specifying HTTP versions (#337)Paul (xobb) Chubatyybefore adoption0c4460e
line 13why, one step back13First pass at autodoc support (#464)Tom Christiebefore adoption1ce3cc3
lines 14–15why, one step back14::: httpx.get15 :docstring:Add example of specifying HTTP versions (#337)Paul (xobb) Chubatyybefore adoption0c4460e
line 16why, one step back16First pass at autodoc support (#464)Tom Christiebefore adoption1ce3cc3
lines 17–18why, one step back17::: httpx.options18 :docstring:Add example of specifying HTTP versions (#337)Paul (xobb) Chubatyybefore adoption0c4460e
line 19why, one step back19First pass at autodoc support (#464)Tom Christiebefore adoption1ce3cc3
lines 20–21why, one step back20::: httpx.head21 :docstring:Add example of specifying HTTP versions (#337)Paul (xobb) Chubatyybefore adoption0c4460e
line 22why, one step back22First pass at autodoc support (#464)Tom Christiebefore adoption1ce3cc3
lines 23–34why, one step back23::: httpx.post24 :docstring:2526::: httpx.put27 :docstring:2829::: httpx.patch30 :docstring:3132::: httpx.delete33 :docstring:34Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 35why, one step back35## `AsyncClient`First pass at autodoc support (#464)Tom Christiebefore adoption1ce3cc3
line 36why, one step back36Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 37why, one step back37::: httpx.AsyncClientFirst pass at autodoc support (#464)Tom Christiebefore adoption1ce3cc3
line 38why, one step back38 :docstring:Rename 'close' to 'aclose' on Client (#675)Florimond Mancabefore adoptiond5da743
line 39why, one step back39 :members: headers cookies params request get head options post put patch delete build_request send acloseAdd example of specifying HTTP versions (#337)Paul (xobb) Chubatyybefore adoption0c4460e
lines 40–57why, one step back4041## `Response`4243*An HTTP response.*4445* `def __init__(...)`46* `.status_code` - **int**47* `.reason_phrase` - **str**48* `.http_version` - `"HTTP/2"` or `"HTTP/1.1"`49* `.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
line 58why, one step back58* `.elapsed` - **[timedelta](https://docs.python.org/3/library/datetime.html)**response.elapsed now reflects entire request/response time. (#692)Tom Christiebefore adoption6a1ee0e
line 59why, one step back59 * The amount of time elapsed between sending the request and calling `close()` on the corresponding response received for that request.Add `.elapsed` onto Response objects tracking how long a request took. (#351)Roy Williamsbefore adoption05ac117
lines 60–61why, one step back60 [total_seconds()](https://docs.python.org/3/library/datetime.html#datetime.timedelta.total_seconds) to correctly get61 the total elapsed seconds.Add example of specifying HTTP versions (#337)Paul (xobb) Chubatyybefore adoption0c4460e
lines 62–63why, one step back62* `def .raise_for_status()` - **None**63* `def .json()` - **Any**Rename 'read/close' to 'aread/aclose' on Response (#674)Florimond Mancabefore adoptionf9d18a8
line 64why, one step back64* `def .aread()` - **bytes**Fix out-of-date methods on Response API docs (#673)Florimond Mancabefore adoptione30ec85
lines 65–68why, one step back65* `def .aiter_raw()` - **async bytes iterator**66* `def .aiter_bytes()` - **async bytes iterator**67* `def .aiter_text()` - **async text iterator**68* `def .aiter_lines()` - **async text iterator**Rename 'read/close' to 'aread/aclose' on Response (#674)Florimond Mancabefore adoptionf9d18a8
line 69why, one step back69* `def .aclose()` - **None**Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999
line 70why, one step back70* `def .anext()` - **Response**Add example of specifying HTTP versions (#337)Paul (xobb) Chubatyybefore adoption0c4460e
lines 71–78why, one step back7172## `Request`7374*An HTTP request. Can be constructed explicitly for more control over exactly75what gets sent over the wire.*7677```python78>>> request = httpx.Request("GET", "https://example.org", headers={'host': 'example.org'})Drop sync (#544)Tom Christiebefore adoption206c537
line 79why, one step back79>>> response = await client.send(request)Add example of specifying HTTP versions (#337)Paul (xobb) Chubatyybefore adoption0c4460e
lines 80–159why, one step back80```8182* `def __init__(method, url, [params], [data], [json], [headers], [cookies])`83* `.method` - **str**84* `.url` - **URL**85* `.content` - **byte** or **byte async iterator**86* `.headers` - **Headers**87* `.cookies` - **Cookies**8889## `URL`9091*A normalized, IDNA supporting URL.*9293```python94>>> url = URL("https://example.org/")95>>> url.host96'example.org'97```9899* `def __init__(url, allow_relative=False, params=None)`100* `.scheme` - **str**101* `.authority` - **str**102* `.host` - **str**103* `.port` - **int**104* `.path` - **str**105* `.query` - **str**106* `.full_path` - **str**107* `.fragment` - **str**108* `.is_ssl` - **bool**109* `.origin` - **Origin**110* `.is_absolute_url` - **bool**111* `.is_relative_url` - **bool**112* `def .copy_with([scheme], [authority], [path], [query], [fragment])` - **URL**113* `def .resolve_with(url)` - **URL**114115## `Origin`116117*A normalized, IDNA supporting set of scheme/host/port info.*118119```python120>>> Origin('https://example.org') == Origin('HTTPS://EXAMPLE.ORG:443')121True122```123124* `def __init__(url)`125* `.scheme` - **str**126* `.is_ssl` - **bool**127* `.host` - **str**128* `.port` - **int**129130## `Headers`131132*A case-insensitive multi-dict.*133134```python135>>> headers = Headers({'Content-Type': 'application/json'})136>>> headers['content-type']137'application/json'138```139140* `def __init__(self, headers)`141142## `Cookies`143144*A dict-like cookie store.*145146```python147>>> cookies = Cookies()148>>> cookies.set("name", "value", domain="example.org")149```150151* `def __init__(cookies: [dict, Cookies, CookieJar])`152* `.jar` - **CookieJar**153* `def extract_cookies(response)`154* `def set_cookie_header(request)`155* `def set(name, value, [domain], [path])`156* `def get(name, [domain], [path])`157* `def delete(name, [domain], [path])`158* `def clear([domain], [path])`159* *Standard mutable mapping interface*