# @automationcloud/request

> An HTTP client

Latest version **3.4.0** (published 2022-03-14) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @automationcloud/request
pnpm add @automationcloud/request
yarn add @automationcloud/request
bun add @automationcloud/request
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.4.0 |
| Published | 2022-03-14 |
| First published | 2020-07-23 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 71.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | UBIO Limited |
| Maintainers | randunel, mgubio, andrew-waters, inca, nicck, anatoliy |
| Keywords | http, node-fetch, request |

## Links

- npm: https://www.npmjs.com/package/@automationcloud/request
- Repository: https://github.com/automationcloud/autopilot
- Homepage: https://github.com/automationcloud/request#readme
- Issues: https://github.com/automationcloud/request/issues
- npm.io page: https://npm.io/package/@automationcloud/request

## Dependencies (3)

- [node-fetch](https://npm.io/package/node-fetch.md) ^2.6.1
- [oauth-1.0a](https://npm.io/package/oauth-1.0a.md) ^2.2.6
- [@types/node-fetch](https://npm.io/package/@types/node-fetch.md) ^2.5.3

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 3.4.0 (latest) — 2022-03-14
- 3.3.3 — 2021-05-04
- 3.3.2 — 2021-04-12
- 3.3.1 — 2021-03-22
- 3.3.0 — 2021-03-22
- 3.2.1 — 2021-02-05
- 3.2.0 — 2021-01-19
- 3.1.0 — 2021-01-19
- 3.0.6 — 2020-11-03
- 3.0.5 — 2020-10-23
- 3.0.4 — 2020-10-23
- 3.0.3 — 2020-10-19
- 3.0.2 — 2020-10-19
- 3.0.1 — 2020-10-15
- 3.0.0 — 2020-10-15
- … 18 more at https://npm.io/package/@automationcloud/request/versions

## README

# @automationcloud/request

```ts
import { Request } from '@automationcloud/request';

const request = new Request({
  baseUrl: 'https://example.com',
  headers: {
    'common-headers': 'foo'
  },

});

// JSON request shortcuts
const json = await request.post('/foo', {
  query,
  headers,
  body,
});

// Generic
const response = await request.post({
  method: 'POST',
  url: '/bar',
  headers: { ... },
  body: string | Buffer | URLSearchParams,
});
```

## Request Options
all options are optional, values used below example are default values.
```ts
const request = new Request({
    // The base url
    baseUrl: 'https://example.com',

    // auth agent. when you want it to manage the auth stuff.
    // e.g. BasicAuthAgent will set headers.authorization = `Basic ...` automatically when sending a request
    auth: new NoneAuthAgent();

    // default to 10.
    retryAttempts: 10;

    // interval between retries
    retryDelay: 500,

    // The HTTP response status codes that will automatically be retried.
    // Along with status codes, requests will be retried when it fails with predefined network error codes
    // see NETWORK_ERRORS in  src/main/request.ts
    statusCodesToRetry: [401, 429, [502, 504]],

    // The HTTP response status codes that will invalidate the auth.
    // It's going to be used by AuthAgent that implements invalidate method, such as OAuth2Agent
    statusCodeToInvalidateAuth: [401, 403],

    // some default headers to add to requests
    headers: {},

    // fetch module - default to node-fetch
    fetch: nodeFetch,

    // callback function which will be called on retry
    onRetry: () => {},

    // callback function which will be called on error
    onError: () => {},
});

```

---
_Source: https://npm.io/package/@automationcloud/request · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
