This module allows link manipulation within JSON API documents. It expects to work with valid JSON API objects, so review the spec before using this module.
var linker = require('jsonapi-linker');
var doc = linker.rewriteLinks('http://public-url.example.com', {
links: {
self: 'http://origin-url.example.com/things/1'
},
// ...
});
/**
{
links: {
self: 'http://public-url.example.com/things/1'
},
// ...
}
*/
You may also designate a prefix to remove from the original string, e.g.:
var doc = linker.rewriteLinks('http://public-url.example.com', '/api/v1', {
links: {
self: 'http://origin-url.example.com/api/v1/things/1'
},
// ...
});
/**
{
links: {
self: 'http://public-url.example.com/things/1'
},
// ...
}
*/