Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update doc examples for RequestUrl/ResponseUrl #48

Merged
merged 2 commits into from
Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions docs/advanced/additional-requests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ a generic HTTP Request: :class:`~.HttpRequest`. Here's an example:
).encode("utf-8"),
)

print(request.url) # https://www.api.example.com/product-pagination/
print(request.method) # POST
print(request.url) # https://www.api.example.com/product-pagination/
print(type(request.url)) # <class 'web_poet.page_inputs.http.RequestUrl'>
print(request.method) # POST

print(type(request.headers) # <class 'web_poet.page_inputs.HttpRequestHeaders'>
print(request.headers) # <HttpRequestHeaders('Content-Type': 'application/json;charset=UTF-8')>
Expand All @@ -67,7 +68,8 @@ a generic HTTP Request: :class:`~.HttpRequest`. Here's an example:

There are a few things to take note here:

* ``url`` and ``method`` are simply **strings**.
* ``method`` is simply a **string**.
* ``url`` is represented by the :class:`~.RequestUrl` class.
* ``headers`` is represented by the :class:`~.HttpRequestHeaders` class which
resembles a ``dict``-like interface. It supports case-insensitive header-key
lookups as well as multi-key storage.
Expand All @@ -90,8 +92,9 @@ it's perfectly fine to define them as:

request = web_poet.HttpRequest("https://api.example.com/product-info?id=123")

print(request.url) # https://api.example.com/product-info?id=123
print(request.method) # GET
print(request.url) # https://api.example.com/product-info?id=123
print(type(request.url)) # <class 'web_poet.page_inputs.http.RequestUrl'>
print(request.method) # GET

print(type(request.headers) # <class 'web_poet.page_inputs.HttpRequestHeaders'>
print(request.headers) # <HttpRequestHeaders()>
Expand Down Expand Up @@ -141,8 +144,8 @@ Let's check out an example to see its internals:
headers={"Content-Type": "application/json;charset=UTF-8"}
)

print(response.url) # https://www.api.example.com/product-pagination/
print(type(response.url)) # <class 'str'>
print(response.url) # https://www.api.example.com/product-pagination/
print(type(response.url)) # <class 'web_poet.page_inputs.http.ResponseUrl'>

print(response.body) # b'{"data": "value \xf0\x9f\x91\x8d"}'
print(type(response.body)) # <class 'web_poet.page_inputs.HttpResponseBody'>
Expand Down Expand Up @@ -174,7 +177,8 @@ methods.

Here are the key take aways from the example above:

* The ``url`` and ``status`` are simply **string** and **int** respectively.
* ``status`` is simply an **int**.
* ``url`` is represented by the :class:`~.ResponseUrl` class.
* ``headers`` is represented by the :class:`~.HttpResponseHeaders` class.
It's similar to :class:`~.HttpRequestHeaders` where it inherits from
:external:py:class:`multidict.CIMultiDict`, granting it case-insensitive
Expand Down
2 changes: 1 addition & 1 deletion docs/intro/from-ground-up.rst
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ For example, a very basic Page Object could look like this:

def to_item(self) -> dict:
return {
'url': self.response.url,
'url': str(self.response.url),
'title': self.response.css("h1::text").get()
}

Expand Down