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
1
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

  • 6.0.5
  • Source
  • npm
  • Socket score

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

API Client

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

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_urlString Fully qualified uri string used as the base urlYes
circuit_breaker_configObjectThe circuit breaker config. Please refer to this documentation for details.Yes
loggerBunyanBunyan loggerYes
opt_optionsObject-No
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

The rest of the options match the options from the request HTTP client module and can be seen there.

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,
  num_buckets: 10,
  timeout_duration: 3000,
  error_threshold: 50,
  volume_threshold: 5
};

var api_client = api_client_factory.createClient({
  base_url: 'http://api.machinetohuman.com', 
  circuit_breaker_config: config, 
  logger: bunyan_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)
  });
  

Keywords

FAQs

Package last updated on 10 Mar 2016

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