1.0.16 • Published 9 years ago
hyper-path v1.0.16
hyper-path
Traverse a hyper api
Installation
Node
$ npm install hyper-path
Component
$ component install hypergroup/hyper-path
Usage
var client = require('hyper-path');
/**
* create a agent
*/
function agent(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
.
function agent(fn) {
// make a request here
return function unsubscribe() {
// implement me!
}
}
agent.get = function(href, fn) {
// make a request here
return function unsubscribe() {
// implement me!
}
}
var req = client('.path.to.desired.property', agent)
.on(function(err, property) {
// this function will be called anytime any intermediate paths change
});
// stop listening to api changes
req.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.
var req = client('local.remote', agent)
.on(function(err, remote) { });
req.scope({local: {href: '/new/path/to/other/resource'}});
Tests
$ npm install
$ npm test
1.0.16
9 years ago
1.0.15
9 years ago
1.0.14
9 years ago
1.0.13
9 years ago
1.0.12
9 years ago
1.0.11
9 years ago
1.0.10
9 years ago
1.0.9
9 years ago
1.0.8
10 years ago
1.0.6
10 years ago
1.0.5
10 years ago
1.0.4
10 years ago
1.0.3
10 years ago
1.0.2
10 years ago
1.0.1
10 years ago
1.0.0
10 years ago
0.1.7
10 years ago
0.1.3
10 years ago
0.1.2
10 years ago
0.1.0
10 years ago