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

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>)

Properties

abortSignal

Signal of an abort controller. Can be used to abort both sending a network request and waiting for a response.

body

Request body.

decompressResponse

Whether or not to decompress response according to Accept-Encoding header (node-fetch only)

formData

Form data, used to build the request body.

headers

HTTP headers.

keepAlive

Whether to keep the HTTP connections alive throughout requests.

method

HTTP method to use.

onDownloadProgress

Callback which fires upon download progress.

onUploadProgress

Callback which fires upon upload progress.

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.

operationSpec

Specification of the HTTP request.

proxySettings

What proxy to use, if necessary.

query

Query added to the URL.

requestId

Unique identifier of the outgoing request.

shouldDeserialize

Whether or not the HttpOperationResponse should be deserialized. If this is undefined, then the HttpOperationResponse should be deserialized.

spanOptions

Tracing: Options used to create a span when tracing is enabled.

streamResponseBody

Whether or not the body of the HttpOperationResponse should be treated as a stream.

streamResponseStatusCodes

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.

tracingContext

Tracing: Context used when creating Spans.

url

URL of the outgoing request.

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.

Methods

clone()

Clone this WebResource HTTP request object.

prepare(RequestPrepareOptions)

Prepares the request.

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.

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

HTTP headers.

headers: HttpHeadersLike

Property Value

keepAlive

Whether to keep the HTTP connections alive throughout requests.

keepAlive?: boolean

Property Value

boolean

method

HTTP method to use.

method: HttpMethods

Property Value

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

Specification of the HTTP request.

operationSpec?: OperationSpec

Property Value

proxySettings

What proxy to use, if necessary.

proxySettings?: ProxySettings

Property Value

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

@azure/core-tracing.SpanOptions

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

@azure/core-tracing.Context

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()