@mfgx/shared-lib-http-client-core
v3.35.0
Published
An HTTP client that allows deferred execution of HTTP requests.
Downloads
3
Readme
MFGx HTTP Client
This package contains an HTTP client implementation that leverages axios to allow deferred execution of HTTP requests.
Shared Type Definitions
HttpMethod :: head | options | get | post | put | patch | delete
HttpBody :: null | String | Buffer | Blob | ReadableStream
HttpEnvironment :: { httpRequest: { url: String, headers?: Object, serializer?: a -> HttpBody, timeout?: Int, maxContentLength?: Int, keepAlive?: Boolean, retry?: RetryOptions } }
HttpResponse :: { statusCode: Int, statusText: String, body: a, headers: Object }
HttpError :: { message: String, stack: String, info: { response: HttpResponse } }
httpRequest
Given a method and a body, this function returns a ReaderT of Async that accepts the remaining HTTP options in its environment.
By default, the retry options are configured with retries set to 0 and a retryIf function that will trigger for any of the following errors or status codes:
Errors: ['socket hang up', 'ECONNRESET', 'ETIMEDOUT', 'EADDRINUSE', 'ECONNREFUSED', 'EPIPE', 'ENOTFOUND', 'ENETUNREACH', 'EAI_AGAIN'] Status Codes: [408, 502, 503, 504]
If you set retries to a number above 0, you'll be enable retrying based on the conditions above.
In addition, by default, the body is assumed to be JSON and will be serialized with JSON.stringify.
httpRequest :: HttpMethod -> a -> ReaderT HttpEnvironment (Async HttpError HttpResponse)
httpHead
This method is eager because a head request should not have a body. It directly takes an HTTP environment and executes it, with the HTTP method set to head.
httpHead :: HttpEnvironment -> Async HttpError HttpResponse
httpOptions
This method is eager because an options request should not have a body. It directly takes an HTTP environment and executes it, with the HTTP method set to options.
httpOptions :: HttpEnvironment -> Async HttpError HttpResponse
httpGet
This method is eager because a get request should not have a body. It directly takes an HTTP environment and executes it, with the HTTP method set to get.
httpGet :: HttpEnvironment -> Async HttpError HttpResponse
httpPost
Given a body, this function returns a ReaderT of Async that accepts the remaining HTTP options in its environment. The HTTP method is set to post.
httpPost :: a -> ReaderT HttpEnvironment (Async HttpError HttpResponse)
httpPut
Given a body, this function returns a ReaderT of Async that accepts the remaining HTTP options in its environment. The HTTP method is set to put.
httpPut :: a -> ReaderT HttpEnvironment (Async HttpError HttpResponse)
httpPatch
Given a body, this function returns a ReaderT of Async that accepts the remaining HTTP options in its environment. The HTTP method is set to patch.
httpPatch :: a -> ReaderT HttpEnvironment (Async HttpError HttpResponse)
httpDelete
Given a body, this function returns a ReaderT of Async that accepts the remaining HTTP options in its environment. The HTTP method is set to delete.
httpDelete :: a -> ReaderT HttpEnvironment (Async HttpError HttpResponse)