Gangway
A client-side API abstraction layer
Gangway is our general purpose tool for working with APIs on the
client-side. It is a thin layer on top of superagent
with specific
opinions related to how we work.
Overview
Gangway is a factory function that progressively layers configuration
options for building an AJAX request with superagent
:
let Gangway = require('../src')
let API = Gangway({
baseURL: 'http://example.com',
headers: {
'x-api-key': 'your-token-for-every-request'
}
})
API.route({
users: {
get: {
method : 'GET',
path : '/users/{id*}'
}
}
})
API.users.read()
API.users.read({ params: { id: '10' } })
Documentation
Available options
baseURL : The base URL prepended to all requests
body : The request body
method : Request method (GET, POST, PUT, PATCH, DELETE, etc...)
onResponse : Run before resolving a request for preprocessing data
params : Populate bindings in paths and are sent as request bodies. Defaults to body.
path : The path fragment of the endpoint, appended to baseURL
type : Content type, defaults to JSON