Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ganomede-base-client

Package Overview
Dependencies
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ganomede-base-client

Simple wrapper for restify.JsonClient

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

ganomede-base-client

Simple wrapper around restify.JsonClient to start with when writing own API Clients. Changes:

  • single request()-like method (#apiCall({method, path, body, headers, qs}, callback)), meaning:
    • base urls;
    • per request headers;
    • easier query string;
  • supports path prefixes (useful if you want to have something like /api/v1 in front of all requests);
  • if body or qs contain req_id param, sets x-request-id header to value of it.

Basic Usage

Import BaseClient and define higher-level APIs.

const BaseClient = require('ganomede-base-client');

class MyApi extends BaseClient {
  constructor ({hostname = 'my-api.example.org', version = 1, apiKey}) {
    super(
      `https://${hostname}/version-${version}`,  // base url
      {headers: {'X-API-Key': apiKey}}           // more options
    );
  }

  ping (callback) {
    // Will issue HTTP GET to
    // https://my-api.example.org/version-1/ping?check-auth=1
    //
    // Callback will contain JSON response (if any, otherwise empty object),
    // see restify docs for more details at:
    // https://github.com/restify/clients
    //
    // `call` is what restify methods return (like #get(), #post(), etc.).
    const call = this.apiCall(
      {method: 'get', path: '/ping', qs: {'check-auth': 1}},
      callback
    );
  }
}

Custom defaults

Some defaults are changed from those of restify:

  • up to 3 attempts on establishing TCP connections with exponential timeout between 1 and 5 seconds;
  • default headers:
    • accept of application/json;
    • accept-encoding of gzip,deflate.

FAQs

Package last updated on 10 Apr 2017

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