From df7a50c567e60fb9daabc65406f7c0c5129aa76a Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Mon, 24 Feb 2020 23:08:05 +0530 Subject: [PATCH 1/3] Update docs/compatibility.md * Add prepare_request equivalent of httpx to compatibility document * Add difference b/w httpx.Request and requests.Request arguments to compatibility document --- docs/compatibility.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/compatibility.md b/docs/compatibility.md index 89235b1262..833066bb40 100644 --- a/docs/compatibility.md +++ b/docs/compatibility.md @@ -64,6 +64,20 @@ is generally equivalent to client = httpx.Client(**kwargs) ``` +The HTTPX equivalent of `prepare_request` of `requests.Session` instance is `build_request` of `httpx.Client`. + +## Request arguments + +The `Request` class of `httpx` takes the arguments + +`(method, url, params=None, headers=None, cookies=None, data=None, files=None, json=None, stream=None)` + +where as `requests.Request` takes the arguments + +`(method, url, params=None, data=None, json=None, headers=None, cookies=None, files=None, auth=None, timeout=None, allow_redirects=True, proxies=None, verify=True, stream=None, cert=None)` + +The list of arguments that are not present in `httpx.Request` class are `auth`, `timeout`, `allow_redirects`, `proxies`, `verify` and `cert` however these are available in `httpx.request`, `httpx.get`, `httpx.post` etc. + ## Mocking If you need to mock HTTPX the same way that test utilities like `responses` and `requests-mock` does for `requests`, see [RESPX](https://github.com/lundberg/respx). From 495457d830bd05a08180b0dc4dff2b5394466e2d Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Tue, 25 Feb 2020 21:59:04 +0530 Subject: [PATCH 2/3] Update docs/compatibility.md * Remove Request arguments section * Add new section Request instantiation with necessary info --- docs/compatibility.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/docs/compatibility.md b/docs/compatibility.md index 833066bb40..033dfcca43 100644 --- a/docs/compatibility.md +++ b/docs/compatibility.md @@ -64,17 +64,22 @@ is generally equivalent to client = httpx.Client(**kwargs) ``` -The HTTPX equivalent of `prepare_request` of `requests.Session` instance is `build_request` of `httpx.Client`. +## Request instantiation -## Request arguments +Whenever you get a `Response` from an API call, the `request` attribute is actually the `Request` that was used internally. There are cases in which you want to build a `Request` object but don't want to send it immediately. Here is how you can do it. -The `Request` class of `httpx` takes the arguments +```python +req = httpx.Request("GET", "https://example.org") +``` -`(method, url, params=None, headers=None, cookies=None, data=None, files=None, json=None, stream=None)` +The above request object is ready to be sent. There’s no need for `prepare_request()` in HTTPX. -where as `requests.Request` takes the arguments +```python +with httpx.Client() as client: + r = client.send(req) +``` -`(method, url, params=None, data=None, json=None, headers=None, cookies=None, files=None, auth=None, timeout=None, allow_redirects=True, proxies=None, verify=True, stream=None, cert=None)` +If you need to build a request while applying client defaults, see [here](https://www.python-httpx.org/advanced/#build-request). The list of arguments that are not present in `httpx.Request` class are `auth`, `timeout`, `allow_redirects`, `proxies`, `verify` and `cert` however these are available in `httpx.request`, `httpx.get`, `httpx.post` etc. From 5103fd561826634a9033c63828dc4d1eda46f488 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Thu, 26 Mar 2020 01:29:48 +0530 Subject: [PATCH 3/3] Update docs/compatibility.md Commit the suggested changes Co-Authored-By: Florimond Manca --- docs/compatibility.md | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/docs/compatibility.md b/docs/compatibility.md index 033dfcca43..c827f35221 100644 --- a/docs/compatibility.md +++ b/docs/compatibility.md @@ -66,22 +66,9 @@ client = httpx.Client(**kwargs) ## Request instantiation -Whenever you get a `Response` from an API call, the `request` attribute is actually the `Request` that was used internally. There are cases in which you want to build a `Request` object but don't want to send it immediately. Here is how you can do it. +There is no notion of [prepared requests](https://requests.readthedocs.io/en/stable/user/advanced/#prepared-requests) in HTTPX. If you need to customize request instantiation, see [Request instances](/advanced#request-instances). -```python -req = httpx.Request("GET", "https://example.org") -``` - -The above request object is ready to be sent. There’s no need for `prepare_request()` in HTTPX. - -```python -with httpx.Client() as client: - r = client.send(req) -``` - -If you need to build a request while applying client defaults, see [here](https://www.python-httpx.org/advanced/#build-request). - -The list of arguments that are not present in `httpx.Request` class are `auth`, `timeout`, `allow_redirects`, `proxies`, `verify` and `cert` however these are available in `httpx.request`, `httpx.get`, `httpx.post` etc. +Besides, `httpx.Request()` does not support the `auth`, `timeout`, `allow_redirects`, `proxies`, `verify` and `cert` parameters. However these are available in `httpx.request`, `httpx.get`, `httpx.post` etc., as well as on [`Client` instances](/advanced#client-instances). ## Mocking