Skip to content

VersionDownloads/weekNode.js CILicenseCodecov Coverage

Adobe I/O Core Networking Lib

Installing

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

Usage

  1. Initialize the SDK
const{ HttpExponentialBackoff, createFetch }=require('@adobe/aio-lib-core-networking')constfetchRetry=newHttpExponentialBackoff()constproxyFetch=createFetch()
  1. Call methods using the initialized SDK
const{ HttpExponentialBackoff, createFetch }=require('@adobe/aio-lib-core-networking')constfetchRetry=newHttpExponentialBackoff()asyncfunctionsdkTest(){returnnewPromise((resolve,reject)=>{fetchRetry.exponentialBackoff(url,requestOptions,retryOptions,retryOn,retryDelay).then((response)=>{if(!response.ok){throwError(reduceError(response))}resolve(response.json())}).catch(err=>{reject(newcodes.ERROR_GET_SOMETHING({ sdkDetails,messageValues: err}))})})}letproxyFetch// this will get the proxy settings from the the HTTP_PROXY or HTTPS_PROXY environment variables, if setproxyFetch=createFetch()// this will use the passed in proxy settings. Embed basic auth in the url, if requiredproxyFetch=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 fetchconstsimpleFetch=createFetch()

Classes

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

ProxyFetch

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

Functions

createFetch([proxyOptions])function

Return the appropriate Fetch function depending on proxy settings.

parseRetryAfterHeader(header)number

Parse the Retry-After header Spec: https://tools.ietf.org/html/rfc7231#section-7.1.3

Typedefs

RetryOptions : object

Fetch Retry Options

ProxyOptions : object

Proxy Auth Options

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

new HttpExponentialBackoff([options])

Creates an instance of HttpExponentialBackoff

ParamTypeDescription
[options]objectconfiguration options
[options.logLevel]stringthe log level to use (default: process.env.LOG_LEVEL or 'info')
[options.logRetryAfterSeconds]numberthe 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.

httpExponentialBackoff.exponentialBackoff(url, requestOptions, [retryOptions], [retryOn], [retryDelay]) ⇒ Promise.<Response>

This function will retry connecting to a url end-point, with exponential backoff. Returns a Promise.

Kind: instance method of HttpExponentialBackoff
Returns: Promise.<Response> - Promise object representing the http response

ParamTypeDescription
urlstringendpoint url
requestOptionsobject | Requestrequest options
[retryOptions]RetryOptions(optional) retry options
[retryOn]function | Array(optional) Function or Array. If provided, will be used instead of the default
[retryDelay]function | number(optional) Function or number. If provided, will be used instead of the default

ProxyFetch

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

Kind: global class

new ProxyFetch(proxyOptions)

Initialize this class with Proxy auth options

ParamTypeDescription
proxyOptionsProxyOptionsthe auth options to connect with

proxyFetch.fetch(resource, options) ⇒ Promise.<Response>

Fetch function, using the configured fetch options, and proxy options (set in the constructor).

Kind: instance method of ProxyFetch
Returns: Promise.<Response> - Promise object representing the http response

ParamTypeDescription
resourcestring | Requestthe url or Request object to fetch from
optionsobjectthe fetch options

createFetch([proxyOptions]) ⇒ function

Return the appropriate Fetch function depending on proxy settings.

Kind: global function
Returns: function - the Fetch API function

ParamTypeDescription
[proxyOptions]ProxyOptionsthe proxy options

parseRetryAfterHeader(header) ⇒ number

Parse the Retry-After header Spec: https://tools.ietf.org/html/rfc7231#section-7.1.3

Kind: global function
Returns: number - Number of milliseconds to sleep until the next call to getEventsFromJournal

ParamTypeDescription
headerstringRetry-After header value

RetryOptions : object

Fetch Retry Options

Kind: global typedef
Properties

NameTypeDescription
maxRetriesnumberthe maximum number of retries to try (default:3)
initialDelayInMillisnumberthe initial delay in milliseconds (default:100ms)
proxyProxyOptionsthe (optional) proxy auth options

ProxyOptions : object

Proxy Auth Options

Kind: global typedef
Properties

NameTypeDescription
proxyUrlstringthe proxy's url
[username]stringthe username for basic auth
[password]stringthe password for basic auth
rejectUnauthorizedbooleanset to false to not reject unauthorized server certs
[logLevel]stringthe log level to use (default: process.env.LOG_LEVEL or 'info')

Debug Logs

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 for more information.

Licensing

This project is licensed under the Apache V2 License. See LICENSE for more information.

About

This repository contains all HTTP client related Utils to be used by all SDKs

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

5 stars

Watchers

21 watching

Forks

Releases

Packages

Used by

Contributors

Languages