Skip to content
Myr

api.md

This file

Path

docs/api.md

161 lines · 4.0 KiB · Markdown

Last changed by

Add `response.next_request` (#1334)Tom Christiebefore adoption3f51392

History of this file

Take it

The walk stopped after 200 commits: lines older than 8c84210 point at it.

Increased test coverage & cleanup (#1003)Josep Cugatbefore adoption8c84210

lines 1–33why, one step back
1# Developer Interface
23## 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.1011::: httpx.request12 :docstring:1314::: httpx.get15 :docstring:1617::: httpx.options18 :docstring:1920::: httpx.head21 :docstring:2223::: httpx.post24 :docstring:2526::: httpx.put27 :docstring:2829::: httpx.patch30 :docstring:3132::: httpx.delete33 :docstring:

Add `response.next_request` (#1334)Tom Christiebefore adoption3f51392

line 34why, one step back
34

Add stream docstring (#1200)Joebefore adoption924fa8c

lines 35–36why, one step back
35::: httpx.stream
36 :docstring:

Increased test coverage & cleanup (#1003)Josep Cugatbefore adoption8c84210

lines 37–41why, one step back
37
38## `Client`3940::: httpx.Client41 :docstring:

Add stream docstring (#1200)Joebefore adoption924fa8c

line 42why, one step back
42 :members: headers cookies params auth request get head options post put patch delete stream build_request send close

Increased test coverage & cleanup (#1003)Josep Cugatbefore adoption8c84210

lines 43–47why, one step back
43
44## `AsyncClient`4546::: httpx.AsyncClient47 :docstring:

Add stream docstring (#1200)Joebefore adoption924fa8c

line 48why, one step back
48 :members: headers cookies params auth request get head options post put patch delete stream build_request send aclose

Increased test coverage & cleanup (#1003)Josep Cugatbefore adoption8c84210

lines 49–65why, one step back
49
5051## `Response`5253*An HTTP response.*5455* `def __init__(...)`56* `.status_code` - **int**57* `.reason_phrase` - **str**58* `.http_version` - `"HTTP/2"` or `"HTTP/1.1"`59* `.url` - **URL**60* `.headers` - **Headers**61* `.content` - **bytes**62* `.text` - **str**63* `.encoding` - **str**64* `.is_redirect` - **bool**65* `.request` - **Request**

Add `response.next_request` (#1334)Tom Christiebefore adoption3f51392

line 66why, one step back
66* `.next_request` - **Optional[Request]**

Increased test coverage & cleanup (#1003)Josep Cugatbefore adoption8c84210

lines 67–94why, one step back
67* `.cookies` - **Cookies**
68* `.history` - **List[Response]**69* `.elapsed` - **[timedelta](https://docs.python.org/3/library/datetime.html)**70 * The amount of time elapsed between sending the request and calling `close()` on the corresponding response received for that request.71 [total_seconds()](https://docs.python.org/3/library/datetime.html#datetime.timedelta.total_seconds) to correctly get72 the total elapsed seconds.73* `def .raise_for_status()` - **None**74* `def .json()` - **Any**75* `def .read()` - **bytes**76* `def .iter_raw()` - **bytes iterator**77* `def .iter_bytes()` - **bytes iterator**78* `def .iter_text()` - **text iterator**79* `def .iter_lines()` - **text iterator**80* `def .close()` - **None**81* `def .next()` - **Response**82* `def .aread()` - **bytes**83* `def .aiter_raw()` - **async bytes iterator**84* `def .aiter_bytes()` - **async bytes iterator**85* `def .aiter_text()` - **async text iterator**86* `def .aiter_lines()` - **async text iterator**87* `def .aclose()` - **None**88* `def .anext()` - **Response**8990## `Request`9192*An HTTP request. Can be constructed explicitly for more control over exactly93what gets sent over the wire.*94

Use pycon for Python console code blocks (#1187)Hugo van Kemenadebefore adoptiond10b7cd

line 95why, one step back
95```pycon

Increased test coverage & cleanup (#1003)Josep Cugatbefore adoption8c84210

lines 96–110why, one step back
96>>> request = httpx.Request("GET", "https://example.org", headers={'host': 'example.org'})
97>>> response = client.send(request)98```99100* `def __init__(method, url, [params], [data], [json], [headers], [cookies])`101* `.method` - **str**102* `.url` - **URL**103* `.content` - **byte**, **byte iterator**, or **byte async iterator**104* `.headers` - **Headers**105* `.cookies` - **Cookies**106107## `URL`108109*A normalized, IDNA supporting URL.*110

Use pycon for Python console code blocks (#1187)Hugo van Kemenadebefore adoptiond10b7cd

line 111why, one step back
111```pycon

Increased test coverage & cleanup (#1003)Josep Cugatbefore adoption8c84210

lines 112–134why, one step back
112>>> url = URL("https://example.org/")
113>>> url.host114'example.org'115```116117* `def __init__(url, allow_relative=False, params=None)`118* `.scheme` - **str**119* `.authority` - **str**120* `.host` - **str**121* `.port` - **int**122* `.path` - **str**123* `.query` - **str**124* `.full_path` - **str**125* `.fragment` - **str**126* `.is_ssl` - **bool**127* `.is_absolute_url` - **bool**128* `.is_relative_url` - **bool**129* `def .copy_with([scheme], [authority], [path], [query], [fragment])` - **URL**130131## `Headers`132133*A case-insensitive multi-dict.*134

Use pycon for Python console code blocks (#1187)Hugo van Kemenadebefore adoptiond10b7cd

line 135why, one step back
135```pycon

Increased test coverage & cleanup (#1003)Josep Cugatbefore adoption8c84210

lines 136–147why, one step back
136>>> headers = Headers({'Content-Type': 'application/json'})
137>>> headers['content-type']138'application/json'139```140141* `def __init__(self, headers, encoding=None)`142* `def copy()` - **Headers**143144## `Cookies`145146*A dict-like cookie store.*147

Use pycon for Python console code blocks (#1187)Hugo van Kemenadebefore adoptiond10b7cd

line 148why, one step back
148```pycon

Increased test coverage & cleanup (#1003)Josep Cugatbefore adoption8c84210

lines 149–161why, one step back
149>>> cookies = Cookies()
150>>> cookies.set("name", "value", domain="example.org")151```152153* `def __init__(cookies: [dict, Cookies, CookieJar])`154* `.jar` - **CookieJar**155* `def extract_cookies(response)`156* `def set_cookie_header(request)`157* `def set(name, value, [domain], [path])`158* `def get(name, [domain], [path])`159* `def delete(name, [domain], [path])`160* `def clear([domain], [path])`161* *Standard mutable mapping interface*