Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

restl

Package Overview
Dependencies
Maintainers
2
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

restl - npm Package Compare versions

Comparing version 0.3.2 to 0.3.3

test/integration/follow-hal-template.js

8

changelog.md
ChangeLog
=========
0.3.3 (2017-04-27)
0.3.3 (2017-07-07)
------------------
* #37: Support for templated uris.
0.3.2 (2017-04-27)
------------------
* #33: Support for OAuth2 Bearer token.

@@ -8,0 +14,0 @@

10

lib/client.js

@@ -108,9 +108,11 @@ var url = require('url');

/**
* This funciton is a shortcut for getResource().follow(x);
* This function is a shortcut for getResource().follow(x);
*
* This function returns a resource
* @param {string} rel Relationship
* @param {object} variables Templated variables for templated links.
* @returns {Promise}
*/
follow: function(rel) {
follow: function(rel, variables) {
return this.getResource().follow(rel);
return this.getResource().follow(rel, variables);

@@ -117,0 +119,0 @@ },

@@ -1,9 +0,39 @@

var Link = function(rel, href, type) {
var uriTemplate = require('uri-template');
var url = require('url');
var Link = function(rel, baseHref, href, type, templated) {
this.rel = rel;
this.baseHref = baseHref;
this.href = href;
this.type = type;
this.templated = templated;
};
/**
* Returns the absolute link url, based on it's base and relative url.
*/
Link.prototype.resolve = function() {
return url.resolve(this.baseHref, this.href);
};
/**
* Expands a link template (RFC6570) and resolves the uri
*/
Link.prototype.expand = function(variables) {
var templ, expanded;
if (!this.templated) {
return url.resolve(this.baseHref, this.href);
} else {
templ = uriTemplate.parse(this.href);
expanded = templ.expand(variables);
return url.resolve(this.baseHref, expanded);
}
};
module.exports = Link;

@@ -43,4 +43,6 @@ var Link = require('./link');

relType,
url.resolve(representation.uri, links[ii].href),
links[ii].type
representation.uri,
links[ii].href,
links[ii].type,
links[ii].templated
)

@@ -47,0 +49,0 @@ );

@@ -176,5 +176,10 @@ 'use strict';

*
* Returns a Resource object
* This function can also follow templated uris. You can specify uri
* variables in the optional variables argument.
*
* @param {String} rel Relationship type
* @param {Object} Variables. Only needed for templated uris.
* @return Promise{Resource}
*/
follow: function(rel) {
follow: function(rel, variables) {

@@ -186,7 +191,14 @@ return new FollowablePromise(function(res, rej) {

var href;
if (links.length === 0) {
throw new Error('Relation with type ' + rel + ' not found on resource ' + this.uri);
}
if (links[0].templated) {
href = links[0].expand(variables);
} else {
href = links[0].resolve();
}
var resource = this.client.getResource(
links[0].href
href
);

@@ -193,0 +205,0 @@

{
"name": "restl",
"version": "0.3.2",
"version": "0.3.3",
"description": "Opiniated HAL client.",

@@ -31,3 +31,4 @@ "main": "lib/index.js",

"request": "^2.79.0",
"request-promise-any": "^1.0.3"
"request-promise-any": "^1.0.3",
"uri-template": "^1.0.1"
},

@@ -34,0 +35,0 @@ "devDependencies": {

@@ -281,2 +281,19 @@ Restl - A hypermedia client for nodejs

Lastly, it's possible to follow [RFC6570](https://tools.ietf.org/html/rfc6570)
templated links, using the second argument.
For example, a link specified as:
{ href: "/foo{?a}", templated: true}
May be followed using
```js
resource
.follow('some-templated-link', { a: 'bar'})
```
This would result following a link to the `/foo?a=bar` uri.
#### `Resource.followAll()`

@@ -283,0 +300,0 @@

@@ -11,3 +11,4 @@ {

"auth-basic" : { "href" : "/auth/basic" },
"auth-bearer" : { "href" : "/auth/bearer" }
"auth-bearer" : { "href" : "/auth/bearer" },
"templated" : { "href" : "/templated.json{?foo}", "templated": true }
},

@@ -14,0 +15,0 @@ "title" : "Hal 1",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc