Traverse a hyper api
$ npm install hyper-path$ component install hypergroup/hyper-pathvarclient=require('hyper-path');/** * create a agent */functionagent(fn){// make a request to the root of the api here and call// fn(err, body);}agent.get=function(href,fn){// make a request to the href and call// fn(err, body);}client('.path.to.desired.property',agent).on(function(err,property){// property will be set to the value at the end of the passed path, deliminated with '.'// if any of the intermediate properties are undefined a short-circuit will occur and return `undefined`});Agents can offer subscriptions and call fn anytime the data changes at the href. The methods should return an unsubscribe function so the request can clean itself up when calling off.
functionagent(fn){// make a request herereturnfunctionunsubscribe(){// implement me!}}agent.get=function(href,fn){// make a request herereturnfunctionunsubscribe(){// implement me!}}varreq=client('.path.to.desired.property',agent).on(function(err,property){// this function will be called anytime any intermediate paths change});// stop listening to api changesreq.off();Clients can also use a scope for requests with the scope method.
client('local.remote',agent).scope({local: {href: '/path/to/resource'}}).on(function(err,remote){});The function passed to on will be refreshed anytime the scope is updated.
varreq=client('local.remote',agent).on(function(err,remote){});req.scope({local: {href: '/new/path/to/other/resource'}});$ npm install
$ npm test