WebResource class
Creates a new WebResource object.
This class provides an abstraction over a REST call by being library / implementation agnostic and wrapping the necessary properties to initiate a request.
Constructors
Properties
abort |
Signal of an abort controller. Can be used to abort both sending a network request and waiting for a response. |
body | Request body. |
decompress |
Whether or not to decompress response according to Accept-Encoding header (node-fetch only) |
form |
Form data, used to build the request body. |
headers | HTTP headers. |
keep |
Whether to keep the HTTP connections alive throughout requests. |
method | HTTP method to use. |
on |
Callback which fires upon download progress. |
on |
Callback which fires upon upload progress. |
operation |
A function that returns the proper OperationResponse for the given OperationSpec and HttpOperationResponse combination. If this is undefined, then a simple status code lookup will be used. |
operation |
Specification of the HTTP request. |
proxy |
What proxy to use, if necessary. |
query | Query added to the URL. |
request |
Unique identifier of the outgoing request. |
should |
Whether or not the HttpOperationResponse should be deserialized. If this is undefined, then the HttpOperationResponse should be deserialized. |
span |
Tracing: Options used to create a span when tracing is enabled. |
stream |
Whether or not the body of the HttpOperationResponse should be treated as a stream. |
stream |
A list of status codes whose corresponding HttpOperationResponse body should be treated as a stream. |
timeout | How long to wait in milliseconds before aborting the request. |
tracing |
Tracing: Context used when creating Spans. |
url | URL of the outgoing request. |
with |
Whether to send credentials (via cookies, authorization headers, or TLS client certificates) when making a request in the browser to a cross-site destination. |
Methods
clone() | Clone this WebResource HTTP request object. |
prepare(Request |
Prepares the request. |
validate |
Validates that the required properties such as method, url, headers["Content-Type"], headers["accept-language"] are defined. It will throw an error if one of the above mentioned properties are not defined. |
Constructor Details
WebResource(string, HttpMethods, unknown, {[key: string]: any}, {[key: string]: any} | HttpHeadersLike, boolean, boolean, AbortSignalLike, number, (progress: TransferProgressEvent) => void, (progress: TransferProgressEvent) => void, ProxySettings, boolean, boolean, Set<number>)
new WebResource(url?: string, method?: HttpMethods, body?: unknown, query?: {[key: string]: any}, headers?: {[key: string]: any} | HttpHeadersLike, streamResponseBody?: boolean, withCredentials?: boolean, abortSignal?: AbortSignalLike, timeout?: number, onUploadProgress?: (progress: TransferProgressEvent) => void, onDownloadProgress?: (progress: TransferProgressEvent) => void, proxySettings?: ProxySettings, keepAlive?: boolean, decompressResponse?: boolean, streamResponseStatusCodes?: Set<number>)
Parameters
- url
-
string
- method
- HttpMethods
- body
-
unknown
- query
-
{[key: string]: any}
- headers
-
{[key: string]: any} | HttpHeadersLike
- streamResponseBody
-
boolean
- withCredentials
-
boolean
- abortSignal
- AbortSignalLike
- timeout
-
number
- onUploadProgress
-
(progress: TransferProgressEvent) => void
- onDownloadProgress
-
(progress: TransferProgressEvent) => void
- proxySettings
- ProxySettings
- keepAlive
-
boolean
- decompressResponse
-
boolean
- streamResponseStatusCodes
-
Set<number>
Property Details
abortSignal
Signal of an abort controller. Can be used to abort both sending a network request and waiting for a response.
abortSignal?: AbortSignalLike
Property Value
body
Request body.
body?: any
Property Value
any
decompressResponse
Whether or not to decompress response according to Accept-Encoding header (node-fetch only)
decompressResponse?: boolean
Property Value
boolean
formData
Form data, used to build the request body.
formData?: any
Property Value
any
headers
keepAlive
Whether to keep the HTTP connections alive throughout requests.
keepAlive?: boolean
Property Value
boolean
method
onDownloadProgress
Callback which fires upon download progress.
onDownloadProgress?: (progress: TransferProgressEvent) => void
Property Value
(progress: TransferProgressEvent) => void
onUploadProgress
Callback which fires upon upload progress.
onUploadProgress?: (progress: TransferProgressEvent) => void
Property Value
(progress: TransferProgressEvent) => void
operationResponseGetter
A function that returns the proper OperationResponse for the given OperationSpec and HttpOperationResponse combination. If this is undefined, then a simple status code lookup will be used.
operationResponseGetter?: (operationSpec: OperationSpec, response: HttpOperationResponse) => undefined | OperationResponse
Property Value
(operationSpec: OperationSpec, response: HttpOperationResponse) => undefined | OperationResponse
operationSpec
proxySettings
query
Query added to the URL.
query?: {[key: string]: any}
Property Value
{[key: string]: any}
requestId
Unique identifier of the outgoing request.
requestId: string
Property Value
string
shouldDeserialize
Whether or not the HttpOperationResponse should be deserialized. If this is undefined, then the HttpOperationResponse should be deserialized.
shouldDeserialize?: boolean | (response: HttpOperationResponse) => boolean
Property Value
boolean | (response: HttpOperationResponse) => boolean
spanOptions
Tracing: Options used to create a span when tracing is enabled.
spanOptions?: SpanOptions
Property Value
streamResponseBody
Warning
This API is now deprecated.
Use streamResponseStatusCodes property instead.
Whether or not the body of the HttpOperationResponse should be treated as a stream.
streamResponseBody?: boolean
Property Value
boolean
streamResponseStatusCodes
A list of status codes whose corresponding HttpOperationResponse body should be treated as a stream.
streamResponseStatusCodes?: Set<number>
Property Value
Set<number>
timeout
How long to wait in milliseconds before aborting the request.
timeout: number
Property Value
number
tracingContext
Tracing: Context used when creating Spans.
tracingContext?: Context
Property Value
url
URL of the outgoing request.
url: string
Property Value
string
withCredentials
Whether to send credentials (via cookies, authorization headers, or TLS client certificates) when making a request in the browser to a cross-site destination.
withCredentials: boolean
Property Value
boolean
Method Details
clone()
Clone this WebResource HTTP request object.
function clone(): WebResource
Returns
The clone of this WebResource HTTP request object.
prepare(RequestPrepareOptions)
Prepares the request.
function prepare(options: RequestPrepareOptions): WebResource
Parameters
- options
- RequestPrepareOptions
Options to provide for preparing the request.
Returns
Returns the prepared WebResource (HTTP Request) object that needs to be given to the request pipeline.
validateRequestProperties()
Validates that the required properties such as method, url, headers["Content-Type"], headers["accept-language"] are defined. It will throw an error if one of the above mentioned properties are not defined.
function validateRequestProperties()