APIRequestContext.fetch Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and update context cookies from the response. The method will automatically follow redirects. **Usage** JSON objects can be passed dire
(
self,
url_or_request: typing.Union[str, "Request"],
*,
params: typing.Optional[
typing.Union[typing.Dict[str, typing.Union[str, float, bool]], str]
] = None,
method: typing.Optional[str] = None,
headers: typing.Optional[typing.Dict[str, str]] = None,
data: typing.Optional[typing.Union[typing.Any, bytes, str]] = None,
form: typing.Optional[
typing.Union[typing.Dict[str, typing.Union[str, float, bool]], "FormData"]
] = None,
multipart: typing.Optional[
typing.Union[
typing.Dict[str, typing.Union[bytes, bool, float, str, FilePayload]],
"FormData",
]
] = None,
timeout: typing.Optional[typing.Union[float, datetime.timedelta]] = None,
fail_on_status_code: typing.Optional[bool] = None,
ignore_https_errors: typing.Optional[bool] = None,
max_redirects: typing.Optional[int] = None,
max_retries: typing.Optional[int] = None,
)
| 21109 | ) |
| 21110 | |
| 21111 | async def fetch( |
| 21112 | self, |
| 21113 | url_or_request: typing.Union[str, "Request"], |
| 21114 | *, |
| 21115 | params: typing.Optional[ |
| 21116 | typing.Union[typing.Dict[str, typing.Union[str, float, bool]], str] |
| 21117 | ] = None, |
| 21118 | method: typing.Optional[str] = None, |
| 21119 | headers: typing.Optional[typing.Dict[str, str]] = None, |
| 21120 | data: typing.Optional[typing.Union[typing.Any, bytes, str]] = None, |
| 21121 | form: typing.Optional[ |
| 21122 | typing.Union[typing.Dict[str, typing.Union[str, float, bool]], "FormData"] |
| 21123 | ] = None, |
| 21124 | multipart: typing.Optional[ |
| 21125 | typing.Union[ |
| 21126 | typing.Dict[str, typing.Union[bytes, bool, float, str, FilePayload]], |
| 21127 | "FormData", |
| 21128 | ] |
| 21129 | ] = None, |
| 21130 | timeout: typing.Optional[typing.Union[float, datetime.timedelta]] = None, |
| 21131 | fail_on_status_code: typing.Optional[bool] = None, |
| 21132 | ignore_https_errors: typing.Optional[bool] = None, |
| 21133 | max_redirects: typing.Optional[int] = None, |
| 21134 | max_retries: typing.Optional[int] = None, |
| 21135 | ) -> "APIResponse": |
| 21136 | """APIRequestContext.fetch |
| 21137 | |
| 21138 | Sends HTTP(S) request and returns its response. The method will populate request cookies from the context and |
| 21139 | update context cookies from the response. The method will automatically follow redirects. |
| 21140 | |
| 21141 | **Usage** |
| 21142 | |
| 21143 | JSON objects can be passed directly to the request: |
| 21144 | |
| 21145 | ```python |
| 21146 | data = { |
| 21147 | \"title\": \"Book Title\", |
| 21148 | \"body\": \"John Doe\", |
| 21149 | } |
| 21150 | api_request_context.fetch(\"https://example.com/api/createBook\", method=\"post\", data=data) |
| 21151 | ``` |
| 21152 | |
| 21153 | The common way to send file(s) in the body of a request is to upload them as form fields with `multipart/form-data` |
| 21154 | encoding, by specifiying the `multipart` parameter: |
| 21155 | |
| 21156 | Parameters |
| 21157 | ---------- |
| 21158 | url_or_request : Union[Request, str] |
| 21159 | Target URL or Request to get all parameters from. |
| 21160 | params : Union[Dict[str, Union[bool, float, str]], str, None] |
| 21161 | Query parameters to be sent with the URL. |
| 21162 | method : Union[str, None] |
| 21163 | If set changes the fetch method (e.g. [PUT](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT) or |
| 21164 | [POST](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST)). If not specified, GET method is used. |
| 21165 | headers : Union[Dict[str, str], None] |
| 21166 | Allows to set HTTP headers. These headers will apply to the fetched request as well as any redirects initiated by |
| 21167 | it. |
| 21168 | data : Union[Any, bytes, str, None] |
nothing calls this directly
no test coverage detected