Skip to content

Commit 9287744

Browse files
committed
fix docs on how RequestUrl/ResponseUrl is portrayed
1 parent aad8ae6 commit 9287744

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

docs/advanced/additional-requests.rst

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ a generic HTTP Request: :class:`~.HttpRequest`. Here's an example:
5454
).encode("utf-8"),
5555
)
5656
57-
print(request.url) # RequestUrl('https://www.api.example.com/product-pagination/')
58-
print(request.method) # POST
57+
print(request.url) # https://www.api.example.com/product-pagination/
58+
print(type(request.url)) # <class 'web_poet.page_inputs.http.RequestUrl'>
59+
print(request.method) # POST
5960
6061
print(type(request.headers) # <class 'web_poet.page_inputs.HttpRequestHeaders'>
6162
print(request.headers) # <HttpRequestHeaders('Content-Type': 'application/json;charset=UTF-8')>
@@ -67,7 +68,8 @@ a generic HTTP Request: :class:`~.HttpRequest`. Here's an example:
6768
6869
There are a few things to take note here:
6970
70-
* ``url`` and ``method`` are simply **strings**.
71+
* ``method`` is simply a **string**.
72+
* ``url`` is represented by the :class:`~.RequestUrl` class.
7173
* ``headers`` is represented by the :class:`~.HttpRequestHeaders` class which
7274
resembles a ``dict``-like interface. It supports case-insensitive header-key
7375
lookups as well as multi-key storage.
@@ -90,8 +92,9 @@ it's perfectly fine to define them as:
9092
9193
request = web_poet.HttpRequest("https://api.example.com/product-info?id=123")
9294
93-
print(request.url) # RequestUrl('https://api.example.com/product-info?id=123')
94-
print(request.method) # GET
95+
print(request.url) # https://api.example.com/product-info?id=123
96+
print(type(request.url)) # <class 'web_poet.page_inputs.http.RequestUrl'>
97+
print(request.method) # GET
9598
9699
print(type(request.headers) # <class 'web_poet.page_inputs.HttpRequestHeaders'>
97100
print(request.headers) # <HttpRequestHeaders()>
@@ -141,8 +144,8 @@ Let's check out an example to see its internals:
141144
headers={"Content-Type": "application/json;charset=UTF-8"}
142145
)
143146
144-
print(response.url) # ResponseUrl('https://www.api.example.com/product-pagination/')
145-
print(type(response.url)) # <class 'str'>
147+
print(response.url) # https://www.api.example.com/product-pagination/
148+
print(type(response.url)) # <class 'web_poet.page_inputs.http.ResponseUrl'>
146149
147150
print(response.body) # b'{"data": "value \xf0\x9f\x91\x8d"}'
148151
print(type(response.body)) # <class 'web_poet.page_inputs.HttpResponseBody'>
@@ -174,7 +177,8 @@ methods.
174177

175178
Here are the key take aways from the example above:
176179

177-
* The ``url`` and ``status`` are simply **string** and **int** respectively.
180+
* ``status`` is simply an **int**.
181+
* ``url`` is represented by the :class:`~.ResponseUrl` class.
178182
* ``headers`` is represented by the :class:`~.HttpResponseHeaders` class.
179183
It's similar to :class:`~.HttpRequestHeaders` where it inherits from
180184
:external:py:class:`multidict.CIMultiDict`, granting it case-insensitive
@@ -604,7 +608,7 @@ from the previous subsection named: :ref:`httpclient-get-example`.
604608
except web_poet.exceptions.HttpResponseError as err:
605609
logger.warning(
606610
f"Received a {err.response.status} response status for product ID "
607-
f"'{item['product_id']}' from this URL: {str(err.request.url)}"
611+
f"'{item['product_id']}' from this URL: {err.request.url}"
608612
)
609613
else:
610614
item["images"] = response.css(".product-images img::attr(src)").getall()

0 commit comments

Comments
 (0)