playwright/docs/src/api/class-apirequest.md

85 lines
3.5 KiB
Markdown
Raw Normal View History

# class: APIRequest
2022-07-05 16:24:50 -08:00
* since: v1.16
2021-10-05 17:53:19 -08:00
Exposes API that can be used for the Web API testing. This class is used for creating
[APIRequestContext] instance which in turn can be used for sending web requests. An instance
of this class can be obtained via [`property: Playwright.request`]. For more information
see [APIRequestContext].
2021-10-05 17:53:19 -08:00
## async method: APIRequest.newContext
2022-07-05 16:24:50 -08:00
* since: v1.16
- returns: <[APIRequestContext]>
2021-10-05 17:53:19 -08:00
Creates new instances of [APIRequestContext].
2021-10-05 17:53:19 -08:00
### option: APIRequest.newContext.clientCertificates = %%-context-option-clientCertificates-%%
* since: 1.46
### option: APIRequest.newContext.useragent = %%-context-option-useragent-%%
2022-07-05 16:24:50 -08:00
* since: v1.16
2022-11-21 09:30:32 -08:00
### option: APIRequest.newContext.extraHTTPHeaders = %%-context-option-extrahttpheaders-%%
2022-07-05 16:24:50 -08:00
* since: v1.16
2022-11-21 09:30:32 -08:00
### option: APIRequest.newContext.httpCredentials = %%-context-option-httpcredentials-%%
2022-07-05 16:24:50 -08:00
* since: v1.16
2022-11-21 09:30:32 -08:00
### option: APIRequest.newContext.proxy = %%-browser-option-proxy-%%
2022-07-05 16:24:50 -08:00
* since: v1.16
2022-11-21 09:30:32 -08:00
### option: APIRequest.newContext.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
2022-07-05 16:24:50 -08:00
* since: v1.16
2021-10-05 17:53:19 -08:00
### option: APIRequest.newContext.timeout
2022-07-05 16:24:50 -08:00
* since: v1.16
2021-10-05 17:53:19 -08:00
- `timeout` <[float]>
Maximum time in milliseconds to wait for the response. Defaults to
`30000` (30 seconds). Pass `0` to disable timeout.
### option: APIRequest.newContext.baseURL
2022-07-05 16:24:50 -08:00
* since: v1.16
2021-10-05 17:53:19 -08:00
- `baseURL` <[string]>
Methods like [`method: APIRequestContext.get`] take the base URL into consideration by using the [`URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL) constructor for building the corresponding URL. Examples:
* baseURL: `http://localhost:3000` and sending request to `/bar.html` results in `http://localhost:3000/bar.html`
* baseURL: `http://localhost:3000/foo/` and sending request to `./bar.html` results in `http://localhost:3000/foo/bar.html`
* baseURL: `http://localhost:3000/foo` (without trailing slash) and navigating to `./bar.html` results in `http://localhost:3000/bar.html`
2021-10-05 17:53:19 -08:00
### option: APIRequest.newContext.storageState
2022-07-05 16:24:50 -08:00
* since: v1.16
* langs: js, python
2021-10-05 17:53:19 -08:00
- `storageState` <[path]|[Object]>
- `cookies` <[Array]<[Object]>>
- `name` <[string]>
- `value` <[string]>
- `domain` <[string]>
- `path` <[string]>
- `expires` <[float]> Unix time in seconds.
- `httpOnly` <[boolean]>
- `secure` <[boolean]>
- `sameSite` <[SameSiteAttribute]<"Strict"|"Lax"|"None">>
- `origins` <[Array]<[Object]>>
- `origin` <[string]>
- `localStorage` <[Array]<[Object]>>
- `name` <[string]>
- `value` <[string]>
Populates context with given storage state. This option can be used to initialize context with logged-in information
obtained via [`method: BrowserContext.storageState`] or [`method: APIRequestContext.storageState`]. Either a path to the
2021-10-05 17:53:19 -08:00
file with saved storage, or the value returned by one of [`method: BrowserContext.storageState`] or
[`method: APIRequestContext.storageState`] methods.
2021-10-05 17:53:19 -08:00
### option: APIRequest.newContext.storageState
2022-07-05 16:24:50 -08:00
* since: v1.16
2022-05-23 22:12:57 +03:00
* langs: java, csharp
- `storageState` <[string]>
Populates context with given storage state. This option can be used to initialize context with logged-in information
obtained via [`method: BrowserContext.storageState`] or [`method: APIRequestContext.storageState`]. Either a path to the
file with saved storage, or the value returned by one of [`method: BrowserContext.storageState`] or
[`method: APIRequestContext.storageState`] methods.
### option: APIRequest.newContext.storageStatePath = %%-csharp-java-context-option-storage-state-path-%%
2022-07-05 16:24:50 -08:00
* since: v1.18