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
orqs
containreq_id
param, setsx-request-id
header to value of it.
Basic Usage
Import BaseClient
and define higher-level APIs.
const BaseClient = ;{super`https:///version-` // base urlheaders: 'X-API-Key': apiKey // more options;}{// 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;}
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
ofapplication/json
;accept-encoding
ofgzip,deflate
.