RequestOptions object¶
The RequestOptions object represents options for XHR request.
Properties¶
requestOptions.url¶
string
The URL of the request.
const requestOptions = {
url: 'https://example.com/webapi/endpoint',
method: 'get'
};
const fetchItem = httpRequesterApi.fetch(requestOptions);
requestOptions.method¶
string
The HTTP method of the request. It should be one of the following: get
, post
, put
, delete
.
const requestOptions = {
url: 'https://example.com/webapi/endpoint',
method: 'delete'
};
const fetchItem = httpRequesterApi.fetch(requestOptions);
requestOptions.data (optional)¶
FormData | Record<string, unknown> | unknown
The data to be sent in the request.
const someFormData = new FormData();
const requestOptions = {
url: 'https://example.com/webapi/endpoint',
method: 'post',
data: someFormData
};
const fetchItem = httpRequesterApi.fetch(requestOptions);
requestOptions.cancelToken (optional)¶
any
The cancel token for the request.
requestOptions.repeatOptions (optional)¶
TRequestRepeatOptions
The options for repeating the request. See TRequestRepeatOptions for more details.
const requestOptions = {
url: 'https://example.com/webapi/endpoint',
method: 'post',
repeatOptions: {
maxAttempts: 5,
repeatRequestOnStatusCodes: [500, 502],
attemptDelayInMs: 1000
}
};
const fetchItem = httpRequesterApi.fetch(requestOptions);
requestOptions.cacheOptions (optional)¶
TRequestCacheOptions
The options for caching the request. See TRequestCacheOptions for more details.
const requestOptions = {
url: 'https://example.com/webapi/endpoint',
method: 'post',
cacheOptions: {
type: 'session',
ttlInMs: 3600000
}
};
const fetchItem = httpRequesterApi.fetch(requestOptions);
requestOptions.sanitizeOptions (optional)¶
TSanitizeOptions
The options for sanitizing the response data. See TSanitizeOptions for more details.
const requestOptions = {
url: 'https://example.com/webapi/endpoint',
method: 'post',
sanitizeOptions: {
disable: true
}
};
const fetchItem = httpRequesterApi.fetch(requestOptions);