editor › Globals › HttpRequest
Class: HttpRequest
Promisified version of an http request. (I could not bring it over me to replace 10 lines of code with 260kb of libraries)
This class throws HttpRequestErrors
Hierarchy
- HttpRequest
Index
Properties
Methods
- _applyDefaultHeaders
- _createPromisedXMLHttpRequest
- _sendJson
- delete
- get
- options
- patch
- patchJson
- postBinaryData
- postJson
- putJson
- setDefaultHeader
Properties
Static Private defaultHeaders
▪ defaultHeaders: object
Defined in src/util/HttpRequest/HttpRequest.ts:12
Type declaration:
Methods
Static _applyDefaultHeaders
▸ _applyDefaultHeaders(request: XMLHttpRequest): void
Defined in src/util/HttpRequest/HttpRequest.ts:169
Parameters:
| Name | Type |
|---|---|
request |
XMLHttpRequest |
Returns: void
Static _createPromisedXMLHttpRequest
▸ _createPromisedXMLHttpRequest(resolve: function, reject: function, responseType?: XMLHttpRequestResponseType, timeout?: number): XMLHttpRequest
Defined in src/util/HttpRequest/HttpRequest.ts:130
Parameters:
▪ resolve: function
▸ (response: any): void
Parameters:
| Name | Type |
|---|---|
response |
any |
▪ reject: function
▸ (error: Error): void
Parameters:
| Name | Type |
|---|---|
error |
Error |
▪Optional responseType: XMLHttpRequestResponseType
▪Optional timeout: number
Returns: XMLHttpRequest
Static _sendJson
▸ _sendJson(path: string, json: any, method: string, responseType?: XMLHttpRequestResponseType, timeout?: number): Promise‹unknown›
Defined in src/util/HttpRequest/HttpRequest.ts:81
Parameters:
| Name | Type |
|---|---|
path |
string |
json |
any |
method |
string |
responseType? |
XMLHttpRequestResponseType |
timeout? |
number |
Returns: Promise‹unknown›
Static delete
▸ delete(path: string, responseType?: XMLHttpRequestResponseType, timeout?: number): Promise‹unknown›
Defined in src/util/HttpRequest/HttpRequest.ts:121
Parameters:
| Name | Type |
|---|---|
path |
string |
responseType? |
XMLHttpRequestResponseType |
timeout? |
number |
Returns: Promise‹unknown›
Static get
▸ get(path: string, responseType?: XMLHttpRequestResponseType, timeout?: number): Promise‹any›
Defined in src/util/HttpRequest/HttpRequest.ts:32
see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType
Parameters:
| Name | Type | Description |
|---|---|---|
path |
string | the path of the file |
responseType? |
XMLHttpRequestResponseType | - the required type of response, defaults to 'text'. Other possible values are 'arraybuffer', 'blob', 'document', 'json' |
timeout? |
number | - |
Returns: Promise‹any›
a promise that will resolve with the response or reject with the request object
Static options
▸ options(path: string, responseType?: XMLHttpRequestResponseType, timeout?: number): Promise‹any›
Defined in src/util/HttpRequest/HttpRequest.ts:45
Parameters:
| Name | Type |
|---|---|
path |
string |
responseType? |
XMLHttpRequestResponseType |
timeout? |
number |
Returns: Promise‹any›
Static patch
▸ patch(path: string, json: any, responseType?: XMLHttpRequestResponseType, timeout?: number): Promise‹unknown›
Defined in src/util/HttpRequest/HttpRequest.ts:111
Parameters:
| Name | Type |
|---|---|
path |
string |
json |
any |
responseType? |
XMLHttpRequestResponseType |
timeout? |
number |
Returns: Promise‹unknown›
Static patchJson
▸ patchJson(path: string, json: any, responseType?: XMLHttpRequestResponseType, timeout?: number): Promise‹any›
Defined in src/util/HttpRequest/HttpRequest.ts:63
Parameters:
| Name | Type |
|---|---|
path |
string |
json |
any |
responseType? |
XMLHttpRequestResponseType |
timeout? |
number |
Returns: Promise‹any›
Static postBinaryData
▸ postBinaryData(path: string, data: BodyInit, responseType?: XMLHttpRequestResponseType, timeout?: number): Promise‹any›
Defined in src/util/HttpRequest/HttpRequest.ts:97
Parameters:
| Name | Type |
|---|---|
path |
string |
data |
BodyInit |
responseType? |
XMLHttpRequestResponseType |
timeout? |
number |
Returns: Promise‹any›
Static postJson
▸ postJson(path: string, json: any, responseType?: XMLHttpRequestResponseType, timeout?: number): Promise‹any›
Defined in src/util/HttpRequest/HttpRequest.ts:54
Parameters:
| Name | Type |
|---|---|
path |
string |
json |
any |
responseType? |
XMLHttpRequestResponseType |
timeout? |
number |
Returns: Promise‹any›
Static putJson
▸ putJson(path: string, json: any, responseType?: XMLHttpRequestResponseType, timeout?: number): Promise‹any›
Defined in src/util/HttpRequest/HttpRequest.ts:72
Parameters:
| Name | Type |
|---|---|
path |
string |
json |
any |
responseType? |
XMLHttpRequestResponseType |
timeout? |
number |
Returns: Promise‹any›
Static setDefaultHeader
▸ setDefaultHeader(header: any, value: any): void
Defined in src/util/HttpRequest/HttpRequest.ts:19
Set an header that will be applied for all requests, e.g. authentication information.
Parameters:
| Name | Type | Description |
|---|---|---|
header |
any | - |
value |
any | - |
Returns: void