2021-10-19 07:38:27 -07:00
# class: APIRequest
2022-07-05 16:24:50 -08:00
* since: v1.16
2021-10-05 17:53:19 -08:00
2022-03-21 13:20:17 -07: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
2021-10-19 07:38:27 -07:00
## async method: APIRequest.newContext
2022-07-05 16:24:50 -08:00
* since: v1.16
2021-10-19 07:38:27 -07:00
- returns: < [APIRequestContext]>
2021-10-05 17:53:19 -08:00
2021-10-19 07:38:27 -07:00
Creates new instances of [APIRequestContext].
2021-10-05 17:53:19 -08:00
2021-10-19 07:38:27 -07:00
### 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
2021-10-19 07:38:27 -07: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
2021-10-19 07:38:27 -07: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
2021-10-19 07:38:27 -07: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
2021-10-19 07:38:27 -07: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
2021-10-19 07:38:27 -07: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.
2021-10-19 07:38:27 -07:00
### 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]>
2021-10-19 07:38:27 -07:00
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:
2021-10-14 09:48:53 -07:00
* 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`
2022-01-11 08:50:58 -07:00
* 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
2021-10-19 07:38:27 -07:00
### option: APIRequest.newContext.storageState
2022-07-05 16:24:50 -08:00
* since: v1.16
2021-11-15 14:54:07 -08:00
* 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
2021-10-19 07:38:27 -07:00
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
2021-10-19 07:38:27 -07:00
[`method: APIRequestContext.storageState` ] methods.
2021-10-05 17:53:19 -08:00
2021-11-15 14:54:07 -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
2021-11-15 14:54:07 -08:00
- `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