# @adobe/aio-lib-core-networking

> Adobe I/O Lib Core Networking

Latest version **5.1.0** (published 2025-11-17) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @adobe/aio-lib-core-networking
pnpm add @adobe/aio-lib-core-networking
yarn add @adobe/aio-lib-core-networking
bun add @adobe/aio-lib-core-networking
```

## Health

**Score 45/100 (D)** — status: stable.

Positive: no vulnerabilities.

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

## Facts

| | |
|---|---|
| Version | 5.1.0 |
| Published | 2025-11-17 |
| First published | 2020-02-24 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=18 |
| Dependencies | 8 |
| Unpacked size | 337.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Maintainers | marbec, tripod, garthdb, lazd, adobe-admin, patrickfulton, trieloff, shazron, krisnye, dcpfsdk, natebaldwin, devongovett, aspro83, symanovi, dpfister, stefan-guggisberg, rofe, kptdobe, adobehalls, fullcolorcoder, djaeggi, dylandepass, mhaack, amol-anand, stopp-adobe, doten, duh_schmidt, asthabh23, zdahbi, tuicu, fmeschbe |

## Links

- npm: https://www.npmjs.com/package/@adobe/aio-lib-core-networking
- Repository: https://github.com/adobe/aio-lib-core-networking
- Issues: https://github.com/adobe/aio-lib-core-networking/issues
- npm.io page: https://npm.io/package/@adobe/aio-lib-core-networking

## Dependencies (8)

- [node-fetch](https://npm.io/package/node-fetch.md) ^2.6.4
- [fetch-retry](https://npm.io/package/fetch-retry.md) ^6.0.0
- [proxy-from-env](https://npm.io/package/proxy-from-env.md) ^1.1.0
- [http-proxy-agent](https://npm.io/package/http-proxy-agent.md) ^7
- [https-proxy-agent](https://npm.io/package/https-proxy-agent.md) ^7
- [@adobe/aio-lib-core-config](https://npm.io/package/@adobe/aio-lib-core-config.md) ^5.0.0
- [@adobe/aio-lib-core-errors](https://npm.io/package/@adobe/aio-lib-core-errors.md) ^4.0.0
- [@adobe/aio-lib-core-logging](https://npm.io/package/@adobe/aio-lib-core-logging.md) ^3.0.0

## Recent versions

- 5.1.0 (latest) — 2025-11-17
- 4.1.0-pre.2024-01-08.87a2e7f9 (next) — 2024-01-08
- 5.0.4 — 2025-02-25
- 5.0.3 — 2024-11-14
- 5.0.2 — 2024-06-13
- 5.0.1 — 2024-02-12
- 5.0.0 — 2024-01-10
- 4.1.0 — 2023-03-21
- 4.0.0 — 2023-02-14
- 3.0.0 — 2022-08-19
- 2.0.0-pre.2022-06-06.777d9f64 — 2022-06-06
- 2.0.0 — 2021-10-06
- 1.0.1 — 2020-05-07
- 1.0.0 — 2020-02-24

## README

<!--
Copyright 2021 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
-->

<!--
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
DO NOT update README.md, it is generated.
Modify 'docs/readme_template.md', then run `npm run generate-docs`.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-->

[![Version](https://img.shields.io/npm/v/@adobe/aio-lib-core-networking.svg)](https://npmjs.org/package/@adobe/aio-lib-core-networking)
[![Downloads/week](https://img.shields.io/npm/dw/@adobe/aio-lib-core-networking.svg)](https://npmjs.org/package/@adobe/aio-lib-core-networking)
[![Node.js CI](https://github.com/adobe/aio-lib-core-networking/actions/workflows/node.js.yml/badge.svg)](https://github.com/adobe/aio-lib-core-networking/actions/workflows/node.js.yml)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) 
[![Codecov Coverage](https://img.shields.io/codecov/c/github/adobe/aio-lib-core-networking/master.svg?style=flat-square)](https://codecov.io/gh/adobe/aio-lib-core-networking/)


# Adobe I/O Core Networking Lib

### Installing

```bash
$ npm install @adobe/aio-lib-core-networking
```

### Usage
1) Initialize the SDK

```javascript
const { HttpExponentialBackoff, createFetch } = require('@adobe/aio-lib-core-networking')
const fetchRetry = new HttpExponentialBackoff()
const proxyFetch = createFetch()
```

2) Call methods using the initialized SDK

```javascript

const { HttpExponentialBackoff, createFetch } = require('@adobe/aio-lib-core-networking')
const fetchRetry = new HttpExponentialBackoff()
async function sdkTest() {

  return new Promise((resolve, reject) => {
    fetchRetry.exponentialBackoff(url, requestOptions, retryOptions, retryOn, retryDelay)
    .then((response) => {
      if (!response.ok) {
        throw Error(reduceError(response))
      }
      resolve(response.json())
    })
    .catch(err => {
      reject(
        new codes.ERROR_GET_SOMETHING({ sdkDetails, messageValues: err }))
    })
  }) 
}

let proxyFetch 
// this will get the proxy settings from the the HTTP_PROXY or HTTPS_PROXY environment variables, if set
proxyFetch = createFetch()

// this will use the passed in proxy settings. Embed basic auth in the url, if required
proxyFetch = createFetch({ proxyUrl: 'http://my.proxy:8080' })

// if the proxy settings are not passed in, and not available in the HTTP_PROXY or HTTPS_PROXY environment variables, it falls back to a simple fetch
const simpleFetch = createFetch()
```

## Classes

<dl>
<dt><a href="#HttpExponentialBackoff">HttpExponentialBackoff</a></dt>
<dd><p>This class provides methods to implement fetch with retries.
The retries use exponential backoff strategy
with defaults set to max of 3 retries and initial Delay as 100ms</p>
</dd>
<dt><a href="#ProxyFetch">ProxyFetch</a></dt>
<dd><p>This provides a wrapper for fetch that facilitates proxy auth authorization.</p>
</dd>
</dl>

## Functions

<dl>
<dt><a href="#createFetch">createFetch([proxyOptions])</a> ⇒ <code>function</code></dt>
<dd><p>Return the appropriate Fetch function depending on proxy settings.</p>
</dd>
<dt><a href="#parseRetryAfterHeader">parseRetryAfterHeader(header)</a> ⇒ <code>number</code></dt>
<dd><p>Parse the Retry-After header
Spec: <a href="https://tools.ietf.org/html/rfc7231#section-7.1.3">https://tools.ietf.org/html/rfc7231#section-7.1.3</a></p>
</dd>
</dl>

## Typedefs

<dl>
<dt><a href="#RetryOptions">RetryOptions</a> : <code>object</code></dt>
<dd><p>Fetch Retry Options</p>
</dd>
<dt><a href="#ProxyOptions">ProxyOptions</a> : <code>object</code></dt>
<dd><p>Proxy Auth Options</p>
</dd>
</dl>

<a name="HttpExponentialBackoff"></a>

## HttpExponentialBackoff
This class provides methods to implement fetch with retries.
The retries use exponential backoff strategy
with defaults set to max of 3 retries and initial Delay as 100ms

**Kind**: global class  

* [HttpExponentialBackoff](#HttpExponentialBackoff)
    * [new HttpExponentialBackoff([options])](#new_HttpExponentialBackoff_new)
    * [.exponentialBackoff(url, requestOptions, [retryOptions], [retryOn], [retryDelay])](#HttpExponentialBackoff+exponentialBackoff) ⇒ <code>Promise.&lt;Response&gt;</code>

<a name="new_HttpExponentialBackoff_new"></a>

### new HttpExponentialBackoff([options])
Creates an instance of HttpExponentialBackoff


| Param | Type | Description |
| --- | --- | --- |
| [options] | <code>object</code> | configuration options |
| [options.logLevel] | <code>string</code> | the log level to use (default: process.env.LOG_LEVEL or 'info') |
| [options.logRetryAfterSeconds] | <code>number</code> | the number of seconds after which to log a warning if the Retry-After header is greater than the number of seconds. Set to 0 to disable. |

<a name="HttpExponentialBackoff+exponentialBackoff"></a>

### httpExponentialBackoff.exponentialBackoff(url, requestOptions, [retryOptions], [retryOn], [retryDelay]) ⇒ <code>Promise.&lt;Response&gt;</code>
This function will retry connecting to a url end-point, with
exponential backoff. Returns a Promise.

**Kind**: instance method of [<code>HttpExponentialBackoff</code>](#HttpExponentialBackoff)  
**Returns**: <code>Promise.&lt;Response&gt;</code> - Promise object representing the http response  

| Param | Type | Description |
| --- | --- | --- |
| url | <code>string</code> | endpoint url |
| requestOptions | <code>object</code> \| <code>Request</code> | request options |
| [retryOptions] | [<code>RetryOptions</code>](#RetryOptions) | (optional) retry options |
| [retryOn] | <code>function</code> \| <code>Array</code> | (optional) Function or Array. If provided, will be used instead of the default |
| [retryDelay] | <code>function</code> \| <code>number</code> | (optional) Function or number. If provided, will be used instead of the default |

<a name="ProxyFetch"></a>

## ProxyFetch
This provides a wrapper for fetch that facilitates proxy auth authorization.

**Kind**: global class  

* [ProxyFetch](#ProxyFetch)
    * [new ProxyFetch(proxyOptions)](#new_ProxyFetch_new)
    * [.fetch(resource, options)](#ProxyFetch+fetch) ⇒ <code>Promise.&lt;Response&gt;</code>

<a name="new_ProxyFetch_new"></a>

### new ProxyFetch(proxyOptions)
Initialize this class with Proxy auth options


| Param | Type | Description |
| --- | --- | --- |
| proxyOptions | [<code>ProxyOptions</code>](#ProxyOptions) | the auth options to connect with |

<a name="ProxyFetch+fetch"></a>

### proxyFetch.fetch(resource, options) ⇒ <code>Promise.&lt;Response&gt;</code>
Fetch function, using the configured fetch options, and proxy options (set in the constructor).

**Kind**: instance method of [<code>ProxyFetch</code>](#ProxyFetch)  
**Returns**: <code>Promise.&lt;Response&gt;</code> - Promise object representing the http response  

| Param | Type | Description |
| --- | --- | --- |
| resource | <code>string</code> \| <code>Request</code> | the url or Request object to fetch from |
| options | <code>object</code> | the fetch options |

<a name="createFetch"></a>

## createFetch([proxyOptions]) ⇒ <code>function</code>
Return the appropriate Fetch function depending on proxy settings.

**Kind**: global function  
**Returns**: <code>function</code> - the Fetch API function  

| Param | Type | Description |
| --- | --- | --- |
| [proxyOptions] | [<code>ProxyOptions</code>](#ProxyOptions) | the proxy options |

<a name="parseRetryAfterHeader"></a>

## parseRetryAfterHeader(header) ⇒ <code>number</code>
Parse the Retry-After header
Spec: [https://tools.ietf.org/html/rfc7231#section-7.1.3](https://tools.ietf.org/html/rfc7231#section-7.1.3)

**Kind**: global function  
**Returns**: <code>number</code> - Number of milliseconds to sleep until the next call to getEventsFromJournal  

| Param | Type | Description |
| --- | --- | --- |
| header | <code>string</code> | Retry-After header value |

<a name="RetryOptions"></a>

## RetryOptions : <code>object</code>
Fetch Retry Options

**Kind**: global typedef  
**Properties**

| Name | Type | Description |
| --- | --- | --- |
| maxRetries | <code>number</code> | the maximum number of retries to try (default:3) |
| initialDelayInMillis | <code>number</code> | the initial delay in milliseconds (default:100ms) |
| proxy | [<code>ProxyOptions</code>](#ProxyOptions) | the (optional) proxy auth options |

<a name="ProxyOptions"></a>

## ProxyOptions : <code>object</code>
Proxy Auth Options

**Kind**: global typedef  
**Properties**

| Name | Type | Description |
| --- | --- | --- |
| proxyUrl | <code>string</code> | the proxy's url |
| [username] | <code>string</code> | the username for basic auth |
| [password] | <code>string</code> | the password for basic auth |
| rejectUnauthorized | <code>boolean</code> | set to false to not reject unauthorized server certs |
| [logLevel] | <code>string</code> | the log level to use (default: process.env.LOG_LEVEL or 'info') |

### Debug Logs

```bash
LOG_LEVEL=debug <your_call_here>
```

Prepend the `LOG_LEVEL` environment variable and `debug` value to the call that invokes your function, on the command line. This should output a lot of debug data for your SDK calls.

### Contributing

Contributions are welcome! Read the [Contributing Guide](./.github/CONTRIBUTING.md) for more information.

### Licensing

This project is licensed under the Apache V2 License. See [LICENSE](LICENSE) for more information.

---
_Source: https://npm.io/package/@adobe/aio-lib-core-networking · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
