Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
▪ T
↳ HttpResponseError
+ new HttpResponseError(response
: HttpResponse‹T›, message?
: undefined | string): HttpResponseError
Parameters:
Returns: HttpResponseError
• message: string
Inherited from HttpRequestError.message
• name: string
Inherited from HttpRequestError.name
• response: HttpResponse‹T›
Optional
stack• stack? : undefined | string
Inherited from HttpRequestError.stack
Overrides HttpRequestError.stack
• status: HttpCode
Static
Error▪ Error: ErrorConstructor
Name | Type |
---|---|
response
HttpResponse‹T›
message?
undefined | string
▪ T
↳ HttpRequestError
+ new HttpRequestError(options
: NormalizedHttpOptions, message?
: undefined | string): HttpRequestError
Parameters:
Returns: HttpRequestError
• message: string
Inherited from HttpRequestError.message
• name: string
Inherited from HttpRequestError.name
• options: NormalizedHttpOptions
Optional
stack• stack? : undefined | string
Inherited from HttpRequestError.stack
Overrides HttpRequestError.stack
Static
Error▪ Error: ErrorConstructor
Base class in Coolio http package, which allows to perform API calls.
▪ T
Common body shape defined by bodyParser passed in HttpClientConfig.
HttpClient
+ new HttpClient(config
: HttpClientConfig‹T›): HttpClient
Parameters:
Returns: HttpClient
▸ addInterceptor(interceptor
: HttpInterceptor): this
Adds an interceptor to the client. Interceptor can be written either as class or as a function, which may mutate request options and post-process response from server. Multiple interceptors can be added to a single HttpClient. They can perform as:
cache
error handler
authorizer
logger
auto-retry
redirection handler
Parameters:
Returns: this
▸ delete<Body>(uri
: string, options?
: HttpOptions): Promise‹HttpResponse‹Body››
Performs a DELETE request.
Type parameters:
▪ Body: T
Parameters:
Returns: Promise‹HttpResponse‹Body››
▸ get<Body>(uri
: string, options?
: HttpOptions): Promise‹HttpResponse‹Body››
Performs a GET request.
Type parameters:
▪ Body: T
Parameters:
Returns: Promise‹HttpResponse‹Body››
▸ patch<Body>(uri
: string, options?
: HttpOptions): Promise‹HttpResponse‹Body››
Performs a PATCH request.
Type parameters:
▪ Body: T
Parameters:
Returns: Promise‹HttpResponse‹Body››
▸ post<Body>(uri
: string, options?
: HttpOptions): Promise‹HttpResponse‹Body››
Performs a POST request.
Type parameters:
▪ Body: T
Parameters:
Returns: Promise‹HttpResponse‹Body››
▸ put<Body>(uri
: string, options?
: HttpOptions): Promise‹HttpResponse‹Body››
Performs a PUT request.
Type parameters:
▪ Body: T
Parameters:
Returns: Promise‹HttpResponse‹Body››
▸ remove<Body>(uri
: string, options?
: HttpOptions): Promise‹HttpResponse‹any››
Performs a DELETE request.
deprecated
Use delete instead of remove, since it matches HTTP request method.
Type parameters:
▪ Body: T
Parameters:
Returns: Promise‹HttpResponse‹any››
▸ request<Body>(url
: string, options
: HttpRequestOptions): Promise‹HttpResponse‹Body››
Type parameters:
▪ Body: T
Parameters:
Returns: Promise‹HttpResponse‹Body››
Networking client for Node.js, React Native & browser web apps
Coolio is an environment-agnostic networking client for Node.js, React Native & browser web apps. The aim of Coolio is to abstract out the technical stuff and let developers query APIs in DRY manner. Usually such approach makes simple things easier while making complex use-cases impossible. Coolio gives users more control over networking, allowing to customize almost every step of it's networking pipeline:
sending and handling requests,
body normalization,
pre and postprocessing.
This is achieved by using interceptors concept and providing pluggable interfaces whenever possible.
Coolio is broken down into several packages, allowing you to pick what's really needed.
Most important yarn
scripts during development:
start
- runs builds for all packages in watch mode
verify
- runs lint & tests
Create readable "multipart/form-data" streams. Can be used to submit forms and file uploads to other web applications.
CFormData
Parameters:
Static
DEFAULT_CONTENT_TYPE▪ DEFAULT_CONTENT_TYPE: string = "application/octet-stream"
Static
LINE_BREAK▪ LINE_BREAK: string = " "
Parameters:
Returns: void
▸ delete(name
: string): void
Parameters:
Returns: void
▸ forEach(callbackfn
: function): void
Parameters:
▪ callbackfn: function
Parameters:
Returns: void
Parameters:
Parameters:
▸ getBoundary(): string
Returns: string
▸ getBuffer(): Promise‹Buffer›
Returns: Promise‹Buffer›
▸ getHeaders(): object
Returns: object
content-type: string = 'multipart/form-data; boundary=' + this.getBoundary()
▸ has(name
: string): boolean
Parameters:
Returns: boolean
▸ pipe(writable
: Writable): void
Parameters:
Returns: void
Parameters:
Returns: void
▸ toString(): string
Returns: string
Static
fromParameters:
▪ data: any
▪Default value
__namedParameters: object= {}
Static
isFormData▸ isFormData(data
: any): data is FormData | CFormData
Parameters:
Returns: data is FormData | CFormData
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type | Description |
---|---|---|
Name | Type |
---|---|
+ new HttpResponseHeaders(headers
: IncomingHttpHeaders | | Headers | string):
Name | Type | Default |
---|
Returns:
Name | Type |
---|
Name | Type |
---|
+ new CFormData(data?
: any):
Name | Type |
---|
Returns:
▸ append(name
: string, value
: any, meta?
: ): void
Name | Type |
---|
Name | Type |
---|
▸ (value
: , key
: string, parent
: ): void
Name | Type |
---|
▸ get(name
: string): | null
Name | Type |
---|
Returns: | null
▸ getAll(name
: string): []
Name | Type |
---|
Returns: []
Name | Type |
---|
Name | Type |
---|
▸ set(name
: string, value
: | Blob, meta?
: ): void
Name | Type |
---|
▸ from(data
: any, __namedParameters
: object): FormData |
Name | Type |
---|
Returns: FormData |
Name | Type |
---|
Package
Description
Auth Interceptor with OAuth2 refresh token support for @coolio/http
HTTP networking client
JSON API client
options
message?
undefined | string
config
interceptor
Interceptor that will process every request/response in this HttpClient.
uri
string
Address of HTTP endpoint
options?
Additional HttpOptions passed with request
uri
string
Address of HTTP endpoint
options?
Additional HttpOptions passed with request
uri
string
Address of HTTP endpoint
options?
Additional HttpOptions passed with request
uri
string
Address of HTTP endpoint
options?
Additional HttpOptions passed with request
uri
string
Address of HTTP endpoint
options?
Additional HttpOptions passed with request
uri
string
Address of HTTP endpoint
options?
Additional HttpOptions passed with request
url
string
options
| string |
| string |
| any |
| any |
| string |
| string |
| string |
| string |
| Writable |
| undefined | "native" | "custom" |
| any |
| {} |
| string |
| any |
|
|
| string |
|
| string |
|
|
BodyCasing
ContentType
HttpCode
HttpMethod
ParsedBodyCacheState
CFormData
HttpClient
HttpRequestError
HttpResponseError
HttpResponseHeaders
BodyParserOptions
BodySerializerOptions
CFormDataEntryMetadata
CFormDataEntryValue
Endpoint
FetchRequestHandlerOptions
FormDataFromOptions
HttpClientConfig
HttpInterceptorInterface
HttpRequestHandlerOptions
HttpRequestOptions
HttpResponse
HttpResponseOptions
Log
LoggingInterceptorOptions
MockOptions
NormalizedHttpOptions
RawHttpResponse
RedirectionInterceptorOptions
SimpleServer
XhrRequestHandlerOptions
Ƭ BodyParser: function
▸ (response
: RawHttpResponse): HttpResponse‹T›
Parameters:
Ƭ BodyParserImplementation: function
▸ (rawResponse
: RawHttpResponse): Promise‹any›
Parameters:
Ƭ BodySerializer: function
▸ (request
: HttpOptions): NormalizedHttpBody
Parameters:
Ƭ BufferEncoding: "ascii" | "utf8" | "utf-8" | "utf16le" | "ucs2" | "ucs-2" | "base64" | "latin1" | "binary" | "hex"
Ƭ CFormDataValue: string | Blob | Readable
Ƭ CaseConverter: function
▸ (object
: any): any
Parameters:
Ƭ ContentTypeMap: Record‹keyof typeof ContentTypeRegex, T›
Ƭ HttpBody: object | TypedArray | string
Ƭ HttpFetch: function
▸ (): Promise‹HttpResponse‹Body››
Ƭ HttpHeaders: Record‹string, string | number | boolean | undefined | null›
Ƭ HttpInterceptor: HttpInterceptorFunction | HttpInterceptorInterface
Ƭ HttpInterceptorFunction: function
▸ <Body>(request
: HttpFetch‹Body›, options
: NormalizedHttpOptions): HttpFetch‹Body›
Type parameters:
▪ Body
Parameters:
Ƭ HttpOptions: Partial‹HttpRequestOptions›
Ƭ HttpRequestHandler: function
▸ (requestOptions
: NormalizedHttpOptions): Promise‹RawHttpResponse›
Parameters:
Ƭ MockHttpRequestHandler: HttpRequestHandler & object
Ƭ NormalizedHttpBody: FormData | CFormData | TypedArray | string | undefined
Ƭ PromiseFunction: function
▸ (): Promise‹T›
Ƭ RequestMode: "navigate" | "same-origin" | "no-cors" | "cors"
Const
DEFAULT_REQUEST_TIMEOUT_MS• DEFAULT_REQUEST_TIMEOUT_MS: number = 5 * 60 * 1000
Default request timeout - 5 minutes.
Const
DONE• DONE: 4 = 4
Const
HEADERS_RECEIVED• HEADERS_RECEIVED: 2 = 2
Const
SUPPORTS_BROWSER_FORM_DATA• SUPPORTS_BROWSER_FORM_DATA: boolean = (() => { try { return !({} instanceof FormData); } catch { return false; } })()
• TypedArray: any
Const
symbol• symbol: unique symbol = Symbol('HttpResponseError')
Const
bodyParser▸ bodyParser(__namedParameters
: object): BodyParser‹any›
Parameters:
▪Default value
__namedParameters: object= {}
Returns: BodyParser‹any›
Const
bodySerializer▸ bodySerializer(__namedParameters
: object): BodySerializer
Parameters:
▪Default value
__namedParameters: object= {}
Returns: BodySerializer
Const
cacheParsedBody▸ cacheParsedBody<T>(parsedBody
: PromiseFunction‹T›): PromiseFunction‹T›
This is not a regular cache! This function is only used across subsequent executions of parsedBody() on a single HttpResponse. To implement cache, make use of interceptors.
Type parameters:
▪ T
Parameters:
Returns: PromiseFunction‹T›
a promise function returning body, it can be called many times
Const
createAsyncBodyHandler▸ createAsyncBodyHandler<T>(): object
Type parameters:
▪ T
Returns: object
call(): Promise‹T›
onBodyFailure(failer
: function): void
onBodyReceived(getter
: function): void
Const
createErrorInterceptor▸ createErrorInterceptor(): HttpInterceptorFunction
Returns: HttpInterceptorFunction
Const
createHttpResponse▸ createHttpResponse(__namedParameters
: object): HttpResponse
Parameters:
▪ __namedParameters: object
Returns: HttpResponse
Const
createLoggingInterceptor▸ createLoggingInterceptor(__namedParameters
: object): HttpInterceptorFunction
Parameters:
▪ __namedParameters: object
Returns: HttpInterceptorFunction
Const
createRedirectionInterceptor▸ createRedirectionInterceptor(__namedParameters
: object): HttpInterceptorFunction
Parameters:
▪Default value
__namedParameters: object= {}
Returns: HttpInterceptorFunction
Const
createSimpleServer▸ createSimpleServer(): SimpleServer
Returns: SimpleServer
Const
deepKeyMap▸ deepKeyMap(object
: any, mapper
: function): any
Parameters:
▪ object: any
▪ mapper: function
▸ (key
: string): string
Parameters:
Returns: any
Const
defaultHeaders▸ defaultHeaders(_host
: string): object
Parameters:
Returns: object
Accept: string = "application/json,application/vnd.api+json"
Content-Type: ContentType = ContentType.JSON
Const
encodeArrayBuffer▸ encodeArrayBuffer(data
: TypedArray | string | undefined, encoding
: BufferEncoding): Uint8Array‹›
Parameters:
Returns: Uint8Array‹›
Const
encodeText▸ encodeText(buffer
: ArrayBuffer, encoding
: string): string
Parameters:
Returns: string
Const
fetchRequestHandler▸ fetchRequestHandler(fetchRequestHandlerOptions
: FetchRequestHandlerOptions): HttpRequestHandler
Creates a new HttpRequestHandler that uses Fetch API underneath. Does not support timeout property. Abort is possible only after headers were received.
Parameters:
Returns: HttpRequestHandler
Const
getBoundaryFromContentTypeHeader▸ getBoundaryFromContentTypeHeader(header
: string[]): string
Parameters:
Returns: string
Const
getCaseConverter▸ getCaseConverter(bodyCasing?
: BodyCasing): toCamelCase
Parameters:
Returns: toCamelCase
Const
getEncodingFromHeaders▸ getEncodingFromHeaders(headers
: HttpResponseHeaders | undefined, fallback
: string): string
Parameters:
Returns: string
Const
getFileMeta▸ getFileMeta(value
: Blob | Readable, existingMeta?
: CFormDataEntryMetadata): object | object
Parameters:
Returns: object | object
Const
getHeader▸ getHeader(headers
: HttpHeaders | undefined, header
: string): string | undefined
Parameters:
Returns: string | undefined
Const
getHostname▸ getHostname(url
: string): string
Parameters:
Returns: string
Const
handleRequest▸ handleRequest(code
: number, body
: any, contentType
: string): Promise‹HttpResponse›
Parameters:
Returns: Promise‹HttpResponse›
Const
httpRequestHandler▸ httpRequestHandler(requestHandlerOptions
: HttpRequestHandlerOptions): HttpRequestHandler
Creates a new HttpRequestHandler that uses native Node.js HTTP & HTTPS modules underneath. Does not support mode property.
Parameters:
Returns: HttpRequestHandler
Const
isBlob▸ isBlob(value
: any): value is Blob
Parameters:
Returns: value is Blob
Const
isBrowserFormData▸ isBrowserFormData(value
: any): value is FormData
Parameters:
Returns: value is FormData
Const
isHttpInterceptorInterface▸ isHttpInterceptorInterface(interceptor
: HttpInterceptor): interceptor is HttpInterceptorInterface
Parameters:
Returns: interceptor is HttpInterceptorInterface
Const
isHttpRequestError▸ isHttpRequestError(error
: any): error is HttpRequestError
Parameters:
Returns: error is HttpRequestError
Const
isHttpResponseError▸ isHttpResponseError(error
: any): error is HttpResponseError
Parameters:
Returns: error is HttpResponseError
Const
mockRequestHandler▸ mockRequestHandler(mockOptions
: MockOptions): MockHttpRequestHandler
Parameters:
Returns: MockHttpRequestHandler
Const
noConversion▸ noConversion(object
: any): any
Parameters:
Returns: any
Const
parseHeaders▸ parseHeaders(headers
: Headers): Record‹string, string›
Parameters:
Returns: Record‹string, string›
Const
processMultipartBody▸ processMultipartBody(body
: string, boundary
: string): never
Parameters:
Returns: never
Const
readBlob▸ readBlob(blob
: Blob): Promise‹Buffer›
Parameters:
Returns: Promise‹Buffer›
Const
sanitizeHeaders▸ sanitizeHeaders(...multipleHeaders
: undefined | object[]): Record‹string, string›
Parameters:
Returns: Record‹string, string›
Const
sleep▸ sleep(ms
: number): Promise‹unknown›
Parameters:
Returns: Promise‹unknown›
Const
splitWords▸ splitWords(text
: string): string[]
Parameters:
Returns: string[]
▸ switchContentType<T>(contentType
: string, map
: ContentTypeMap‹T›, defaultResult
: T): T
Type parameters:
▪ T
Parameters:
Returns: T
▸ switchContentType<T>(contentType
: string, map
: ContentTypeMap‹T›): T | undefined
Type parameters:
▪ T
Parameters:
Returns: T | undefined
Const
toCamelCase▸ toCamelCase(object
: any): any
Parameters:
Returns: any
Const
toKebabCase▸ toKebabCase(object
: any): any
Parameters:
Returns: any
Const
toPascalCase▸ toPascalCase(object
: any): any
Parameters:
Returns: any
Const
toScreamingSnakeCase▸ toScreamingSnakeCase(object
: any): any
Parameters:
Returns: any
Const
toSnakeCase▸ toSnakeCase(object
: any): any
Parameters:
Returns: any
Const
toUrlEncoded▸ toUrlEncoded(obj
: object): string
Parameters:
Returns: string
Const
urlCombine▸ urlCombine(sourceUrl
: string, sourceQuery?
: undefined | object, options?
: qs.IStringifyOptions): string
Parameters:
Returns: string
Const
urlDecode▸ urlDecode<T>(value
: string, options?
: qs.IParseOptions): T
Type parameters:
▪ T
Parameters:
Returns: T
Const
urlDestruct▸ urlDestruct(url
: string, options?
: qs.IParseOptions): object
Parameters:
Returns: object
query: any
url: string
Const
urlEncode▸ urlEncode(value
: any, options?
: qs.IStringifyOptions): string
Parameters:
Returns: string
Const
useInterceptor▸ useInterceptor(normalizedOptions
: NormalizedHttpOptions): (Anonymous function)
Parameters:
Returns: (Anonymous function)
Const
xhrRequestHandler▸ xhrRequestHandler(_?
: XhrRequestHandlerOptions): HttpRequestHandler
Parameters:
Returns: HttpRequestHandler
Const
ContentTypeRegex• JSON: RegExp‹› = /^application/(json|.++json)$/
• MULTIPART: RegExp‹› = /^multipart//
• TEXT: RegExp‹› = /^text//
• URL_ENCODED: RegExp‹› = /^application/x-www-form-urlencoded$/
Const
HttpClientHelper• defaultHeaders: defaultHeaders
• getHostname: getHostname
• toUrlEncoded: toUrlEncoded
Const
HttpStatusText• __computed: string = "Network Authentication Required"
Const
Interceptors• createErrorInterceptor: createErrorInterceptor
• createLoggingInterceptor: createLoggingInterceptor
• createRedirectionInterceptor: createRedirectionInterceptor
IncomingHttpHeaders | | Headers | string
| Blob
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type | Description |
---|---|---|
Name | Type | Default |
---|---|---|
Name | Type |
---|---|
Name | Type | Default |
---|---|---|
Name | Type |
---|---|
Name | Type | Default |
---|---|---|
Name | Type | Default |
---|---|---|
Name | Type | Default |
---|---|---|
Name | Type | Default | Description |
---|---|---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type | Default |
---|---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type | Default |
---|---|---|
Name | Type | Default | Description |
---|---|---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
response
RawHttpResponse
rawResponse
RawHttpResponse
request
object
any
request
HttpFetch‹Body›
options
NormalizedHttpOptions
requestOptions
NormalizedHttpOptions
bodyCasing
undefined | CAMEL_CASE | SNAKE_CASE | SCREAMING_SNAKE_CASE | PASCAL_CASE | KEBAB_CASE
customCaseConverter
undefined | function
defaultParser
bodyCasing
undefined | CAMEL_CASE | SNAKE_CASE | SCREAMING_SNAKE_CASE | PASCAL_CASE | KEBAB_CASE
parsedBody
a promise function returning parsed body, which in most cases can be called only once
body
undefined | string | Uint8Array‹› | Uint8ClampedArray‹› | Uint16Array‹› | Uint32Array‹› | Int8Array‹› | Int16Array‹› | Int32Array‹› | Float32Array‹› | Float64Array‹›
-
bodyParserOptions
BodyParserOptions
-
headers
undefined | object
-
status
number
-
url
string
""
logger
function
redirectionLimit
number
30
key
string
_host
string
""
data
TypedArray | string | undefined
""
encoding
"utf8"
buffer
ArrayBuffer
-
encoding
string
"utf8"
fetchRequestHandlerOptions
FetchRequestHandlerOptions
{}
default Fetch API options attached to all requests
header
string[]
bodyCasing?
BodyCasing
headers
HttpResponseHeaders | undefined
-
fallback
string
"utf8"
value
Blob | Readable
existingMeta?
CFormDataEntryMetadata
headers
HttpHeaders | undefined
header
string
url
string
code
number
-
body
any
-
contentType
string
ContentType.TEXT
requestHandlerOptions
HttpRequestHandlerOptions
{}
default native options attached to all requests
value
any
value
any
interceptor
error
any
error
any
mockOptions
MockOptions
object
any
headers
Headers
body
string
boundary
string
blob
Blob
...multipleHeaders
undefined | object[]
ms
number
text
string
contentType
string
map
defaultResult
T
contentType
string
map
object
any
object
any
object
any
object
any
object
any
obj
object
sourceUrl
string
sourceQuery?
undefined | object
options?
qs.IStringifyOptions
value
string
options?
qs.IParseOptions
url
string
options?
qs.IParseOptions
value
any
options?
qs.IStringifyOptions
normalizedOptions
NormalizedHttpOptions
_?
XhrRequestHandlerOptions