Node.js client for hull.io
This provides utility functions to use hull.io APIs within Node.js apps.
Usage
import Hull from 'hull';
const hull = new Hull({
platformId: 'YOUR_HULL_PLATFORM_ID',
platformSecret: 'YOUR_HULL_PLATFORM_SECRET',
orgUrl: 'YOUR_HULL_ORG_URL'
});
Using the HTTP client
Once you have instanciated a client, you can use one of the get
, post
,
put
or delete
methods to perform actions of our APIs.
The first parameter is the route, the second is the set of parameters you want
to send with the request, the third is a callback.
hull.get(path ).then(function(data){
console.log(response);
},function(err, response){
console.log(err);
});
For convenience, we add wrapped=true
to all requests that return a Collection as an Array. You will receive an object in the form :
{
data: [....],
pagination:{
next_url:'xxxx',
last_url:'xxxx',
'total': 1163,
page: 1,
pages: 39,
per_page: 30
}
}
If you want to un-nest the response and receive raw arrays, without pagination, add wrapped:false
to your query
Using the client as a specific user
var user = hull.as('userId');
user.get('/me')
user.userToken()
API
hull.configuration()
: Returns the global configurationhull.as(userId)
: create a new Hull client acting as the userhull.userToken(userHash, claims)
: Creates a signed id for
the user passed in hash. It allows to connect your own users to
hull.io services. userHash needs an email
fieldhull.currentUserId(userId, userSig)
: Checks the
validity of the signature relatively to a user idhull.currentUserMiddleware()
: Generates a middleware
to add to your Connect/Express apps. It will check if a user is onnected.hull.webhookMiddleware()
: Generates a middleware to answer to webhooks
const app = express();
app.use(hull.currentUserMiddleware);
app.use(function(req,res,next){
console.log(req.hull.userId)
})
app.use(hull.webhookMiddleware);
app.use(function(req,res,next){
console.log(req.body)
})