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

153 lines
5.1 KiB
Markdown
Raw Normal View History

2021-10-06 03:53:19 +02:00
# class: ApiRequestContext
* langs: js
2021-10-06 03:53:19 +02:00
This API is used for the Web API testing. You can use it to trigger API endpoints, configure micro-services, prepare
environment or the service to your e2e test. When used on [Page] or a [BrowserContext], this API will automatically use
the cookies from the corresponding [BrowserContext]. This means that if you log in using this API, your e2e test
will be logged in and vice versa.
2021-10-06 03:53:19 +02:00
## async method: ApiRequestContext.dispose
2021-10-06 03:53:19 +02:00
All responses received through [`method: ApiRequestContext.fetch`], [`method: ApiRequestContext.get`], [`method: ApiRequestContext.post`]
and other methods are stored in the memory, so that you can later call [`method: ApiResponse.body`]. This method
discards all stored responses, and makes [`method: ApiResponse.body`] throw "Response disposed" error.
2021-10-06 03:53:19 +02:00
## async method: ApiRequestContext.fetch
- returns: <[ApiResponse]>
Sends HTTP(S) fetch and returns its response. The method will populate fetch cookies from the context and update
context cookies from the response. The method will automatically follow redirects.
2021-10-06 03:53:19 +02:00
### param: ApiRequestContext.fetch.urlOrRequest
- `urlOrRequest` <[string]|[Request]>
Target URL or Request to get all fetch parameters from.
2021-10-06 03:53:19 +02:00
### option: ApiRequestContext.fetch.params
- `params` <[Object]<[string], [string]>>
Query parameters to be send with the URL.
2021-10-06 03:53:19 +02:00
### option: ApiRequestContext.fetch.method
- `method` <[string]>
If set changes the fetch method (e.g. PUT or POST). If not specified, GET method is used.
2021-10-06 03:53:19 +02:00
### option: ApiRequestContext.fetch.headers
- `headers` <[Object]<[string], [string]>>
Allows to set HTTP headers.
2021-10-06 03:53:19 +02:00
### option: ApiRequestContext.fetch.data = %%-fetch-option-data-%%
### option: ApiRequestContext.fetch.form = %%-fetch-option-form-%%
### option: ApiRequestContext.fetch.multipart = %%-fetch-option-multipart-%%
2021-10-06 03:53:19 +02:00
### option: ApiRequestContext.fetch.timeout
- `timeout` <[float]>
Request timeout in milliseconds.
2021-10-06 03:53:19 +02:00
### option: ApiRequestContext.fetch.failOnStatusCode
- `failOnStatusCode` <[boolean]>
Whether to throw on response codes other than 2xx and 3xx. By default response object is returned
for all status codes.
2021-10-06 03:53:19 +02:00
### option: ApiRequestContext.fetch.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
2021-10-06 03:53:19 +02:00
## async method: ApiRequestContext.get
- returns: <[ApiResponse]>
Sends HTTP(S) GET request and returns its response. The method will populate fetch cookies from the context and update
context cookies from the response. The method will automatically follow redirects.
2021-10-06 03:53:19 +02:00
### param: ApiRequestContext.get.url
- `url` <[string]>
Target URL.
2021-10-06 03:53:19 +02:00
### option: ApiRequestContext.get.params
- `params` <[Object]<[string], [string]>>
Query parameters to be send with the URL.
2021-10-06 03:53:19 +02:00
### option: ApiRequestContext.get.headers
- `headers` <[Object]<[string], [string]>>
Allows to set HTTP headers.
2021-10-06 03:53:19 +02:00
### option: ApiRequestContext.get.timeout
- `timeout` <[float]>
Request timeout in milliseconds.
2021-10-06 03:53:19 +02:00
### option: ApiRequestContext.get.failOnStatusCode
- `failOnStatusCode` <[boolean]>
Whether to throw on response codes other than 2xx and 3xx. By default response object is returned
for all status codes.
2021-10-06 03:53:19 +02:00
### option: ApiRequestContext.get.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
2021-10-06 03:53:19 +02:00
## async method: ApiRequestContext.post
- returns: <[ApiResponse]>
Sends HTTP(S) fetch and returns its response. The method will populate fetch cookies from the context and update
context cookies from the response. The method will automatically follow redirects.
2021-10-06 03:53:19 +02:00
### param: ApiRequestContext.post.url
- `url` <[string]>
Target URL.
2021-10-06 03:53:19 +02:00
### option: ApiRequestContext.post.params
- `params` <[Object]<[string], [string]>>
Query parameters to be send with the URL.
2021-10-06 03:53:19 +02:00
### option: ApiRequestContext.post.headers
- `headers` <[Object]<[string], [string]>>
Allows to set HTTP headers.
2021-10-06 03:53:19 +02:00
### option: ApiRequestContext.post.data = %%-fetch-option-data-%%
2021-10-06 03:53:19 +02:00
### option: ApiRequestContext.post.form = %%-fetch-option-form-%%
2021-10-06 03:53:19 +02:00
### option: ApiRequestContext.post.multipart = %%-fetch-option-multipart-%%
2021-10-06 03:53:19 +02:00
### option: ApiRequestContext.post.timeout
- `timeout` <[float]>
Request timeout in milliseconds.
2021-10-06 03:53:19 +02:00
### option: ApiRequestContext.post.failOnStatusCode
- `failOnStatusCode` <[boolean]>
Whether to throw on response codes other than 2xx and 3xx. By default response object is returned
for all status codes.
2021-10-06 03:53:19 +02:00
### option: ApiRequestContext.post.ignoreHTTPSErrors = %%-context-option-ignorehttpserrors-%%
2021-10-06 03:53:19 +02:00
## async method: ApiRequestContext.storageState
- returns: <[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]>
Returns storage state for this request context, contains current cookies and local storage snapshot if it was passed to the constructor.
2021-10-06 03:53:19 +02:00
### option: ApiRequestContext.storageState.path = %%-storagestate-option-path-%%