New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@springworks/api-client

Package Overview
Dependencies
Maintainers
2
Versions
567
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@springworks/api-client

Module for sending requests to other APIs through a circuit breaker

  • 3005.234.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
97
decreased by-86.08%
Maintainers
2
Weekly downloads
 
Created
Source

@springworks/api-client

Module for sending requests to other APIs through a circuit breaker created by @springworks/circuit-breaker-factory.

yarn add @springworks/api-client

API

createClient(params)

Creates a api client using the provided config. Returns an object that exposes a sendRequest(opts, expected_status_codes) function that returns a Promise.

params
NameTypeDescriptionRequired
base_urlStringFully qualified uri string used as the base urlYes
circuit_breaker_configObjectOptional. The circuit breaker config. Please refer to this documentation for details.Yes
loggerLoggerSee @springworks/logger-interfacesYes
authObjectAn object with username and password.No
opt_optionsObjectNo
opt_options.opt_authObjectOptional authentication object that will be used for all requests sent towards the provided base_url. If there is an auth property in the options send in sendRequest then opt_auth gets overwritten.No
opt_options.opt_timeoutNumberTimeout (millis) used in all request from created client.No

sendRequest(options, expected_status_codes)

Sends the request based on the provided options and returns a resolved/rejected Promise.

Options

ParameterDescriptionTypeRequired
endpoint_uriURI of the endpoint that's to be reachedstringYes

expected_status_codes

TypeDescriptionEntries TypeEntries RangeRequired
ArrayExpected status codes by the invoker of this functionNumber[100, 500)Yes

Example Usage

var api_client_factory = require('@springworks/api-client');

var config = {
  source_name: 'my-api',
  target_name: 'facebook-graph-api',
  window_duration: 1000, // optional
  num_buckets: 10, // optional
  timeout_duration: 3000, // optional
  error_threshold: 50, // optional
  volume_threshold: 5, // optional
};

var api_client = api_client_factory.createClient({
  base_url: 'http://api.machinetohuman.com',
  circuit_breaker_config: config,
  logger: logger,
});

var options = {
  endpoint_uri: '/vehicles/1234',
  // other request options
};

var expected_status_codes = [200];

api_client
  .sendRequest(options, expected_status_codes)
  .then(function (response_body) {
    // do your thing;
  })
  .catch(function (err) {
    // err.code is the statusCode of the response or 417 (if responded with code < 400)
  });

FAQs

Package last updated on 02 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc