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
Package
Description
Auth Interceptor with OAuth2 refresh token support for @coolio/http
HTTP networking client
JSON API client
▪ 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››
▪ 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 |
---|---|
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 |
---|---|
Name | Type |
---|---|
+ new HttpResponseHeaders(headers
: IncomingHttpHeaders | | Headers | string):
Name | Type | Default |
---|
Returns:
Name | Type |
---|
Name | Type |
---|
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
response
HttpResponse‹T›
message?
undefined | string
| string |
| string |
| any |
| {} |
Create readable "multipart/form-data" streams. Can be used to submit forms and file uploads to other web applications.
CFormData
+ new CFormData(data?
: any): CFormData
Parameters:
Returns: CFormData
Static
DEFAULT_CONTENT_TYPE▪ DEFAULT_CONTENT_TYPE: string = "application/octet-stream"
Static
LINE_BREAK▪ LINE_BREAK: string = " "
▸ append(name
: string, value
: any, meta?
: CFormDataEntryMetadata): void
Parameters:
Returns: void
▸ delete(name
: string): void
Parameters:
Returns: void
▸ forEach(callbackfn
: function): void
Parameters:
▪ callbackfn: function
▸ (value
: CFormDataValue, key
: string, parent
: CFormData): void
Parameters:
Returns: void
▸ get(name
: string): CFormDataValue | null
Parameters:
Returns: CFormDataValue | null
▸ getAll(name
: string): CFormDataValue[]
Parameters:
Returns: CFormDataValue[]
▸ 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
▸ set(name
: string, value
: CFormDataValue | Blob, meta?
: CFormDataEntryMetadata): void
Parameters:
Returns: void
▸ toString(): string
Returns: string
Static
from▸ from(data
: any, __namedParameters
: object): FormData | CFormData
Parameters:
▪ data: any
▪Default value
__namedParameters: object= {}
Returns: FormData | CFormData
Static
isFormData▸ isFormData(data
: any): data is FormData | CFormData
Parameters:
Returns: data is FormData | CFormData
IncomingHttpHeaders | | Headers | string
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
Name | Type |
---|---|
data?
any
name
string
value
any
meta?
name
string
value
key
string
parent
name
string
name
string
name
string
writable
Writable
name
string
value
CFormDataValue | Blob
meta?
forceImplementation
undefined | "native" | "custom"
data
any