Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Important note: this package is currently pretty experimental and not complete. Use at your own risk.
This NPM package is an attempt at creating a 'generic' hypermedia client, it supports an opiniated set of modern features REST services might have.
This means that there's a strong focus on links and link-relationships.
Initially we'll build in strong support for Web Linking, a.k.a. the HTTP
Link
header, and HAL.
npm install --save restl
_embedded
.Link
header.Prefer: return=representation
.PUT
request.DELETE
request.var restl = require('restl')('http://my-hal-api.example.org/');
// Fetch the home resource
var home = restl.getResource()
// Then get the 'author' relationship from _links
home.follow('author')
.then(function(authorResource)) {
// Follow the 'me' resource.
return authorResource.follow('me');
}.then(function(meResource) {
// Get the full body
return meResource.get();
}.then(function(meBody) {
// Output the body
console.log(meBody);
}).catch(function(err) {
// Error
console.log(err);
});
restl uses request under the hood to do HTTP requests. Custom options can be specified as such:
var bookMark = 'https://my-hal-api.example.org';
var options {
auth: {
user: 'foo',
pass: 'bar'
}
}
var restl = require('restl')(bookMark, options);
For a full list of possible options, check out the request documentation.
var client = new Client(bookMark, options);
bookMark
- The base URL of the web service.options
optional - A list of options for Request.Client.getResource()
Returns a 'Resource' object based on the url. If
var resource = client.getResource(url);
url
- URL to fetch. Might be relative. If not provided, the bookMark is
fetched instead.This function returns a Resource
.
Resource.get()
Returns the result of a GET
request. This function returns a Promise
.
resource.get().then(function(body) {
console.log(body);
});
If the resource was fetched earlier, it will return a cached copy.
Resource.refresh()
Refreshes the internal cache for a resource and does a GET
request again.
This function returns a Promise
that resolves when the operation is complete,
but the Promise
does not have a value.
resource.refresh().then(function() {
return resource.get()
}).then(function(body) {
// A fresh body!
});
Resource.links()
Returns a list of Link
objects for the resource.
resource.links().then(function(links) {
console.log(links);
});
Resource.follow()
Follows a link, by it's relation-type and returns a new resource for the target.
resource.follow('author').then(function(author) {
return author.get();
}).then(function(body) {
console.log(body);
});
FAQs
Opiniated HATEAOS / Rest client.
We found that restl demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.