# @mfgx/shared-lib-http-client-core

> An HTTP client that allows deferred execution of HTTP requests.

Latest version **3.35.0** (published 2021-02-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install @mfgx/shared-lib-http-client-core
pnpm add @mfgx/shared-lib-http-client-core
yarn add @mfgx/shared-lib-http-client-core
bun add @mfgx/shared-lib-http-client-core
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.35.0 |
| Published | 2021-02-11 |
| First published | 2020-05-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 71.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | MFGx, LLC |
| Maintainers | lmenard |

## Links

- npm: https://www.npmjs.com/package/@mfgx/shared-lib-http-client-core
- npm.io page: https://npm.io/package/@mfgx/shared-lib-http-client-core

## Dependencies (8)

- [ramda](https://npm.io/package/ramda.md) 0.26.1
- [crocks](https://npm.io/package/crocks.md) 0.12.4
- [verror](https://npm.io/package/verror.md) 1.10.0
- [cross-fetch](https://npm.io/package/cross-fetch.md) 3.0.4
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) 7.12.5
- [agentkeepalive](https://npm.io/package/agentkeepalive.md) 4.1.4
- [abort-controller](https://npm.io/package/abort-controller.md) 3.0.0
- [@mfgx/shared-lib-crocks-adjunct](https://npm.io/package/@mfgx/shared-lib-crocks-adjunct.md) 3.35.0

## Recent versions

- 3.35.0 (latest) — 2021-02-11
- 3.0.0 — 2020-05-21

## 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)`

---
_Source: https://npm.io/package/@mfgx/shared-lib-http-client-core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
