#mosaic-rest-js
About
This is a js library for Backbase REST API.
Example:
nodejs
var BBRest = require('mosaic-rest-js'),
var bbrest = new BBRest({
portal: 'myPortal'
});
AMD module
require(['bbrest'], function(BBRest) {
var bbrest = new BBRest({
portal: 'myPortal'
});
})
bbrest.server().get().then(function(value) {
if (value.statusCode === 200) {
console.log('Response OK');
}
});
bbrest.server().post('addPortal.xml').then(function(d) {
console.log(d);
});
bbrest.server().put('updatePortal.xml').then(function(d) {
console.log(d);
});
bbrest.catalog().query({ps:5}).get().then(function(d) {
console.log(d);
});
Automation:
npm install // install nodejs dependencies
bower install // install bower dependecies
gulp node // build node distribution file
gulp jquery // build browser jQuery based ditribution file
gulp angular // build browser Angular based ditribution file
gulp min // minify browser distribution files
gulp test-node // run node tests (requires running portal)
gulp test-jq // run jQuery phantomjs tests (requires running portal)
gulp test-ng // run Angular phantomjs tests (requires running portal)
BBRest methods
constructor(config:Object)
BBRest Constructor.
- config - extends default configuration
configuration defaults:
{
host: 'localhost',
port: '7777',
context: 'portalserver',
username: 'admin',
password: 'admin',
portal: null
plugin: null
}
server()
Prepares request on server domain. API Reference
- returns instance of the BBReq
Valid Requests, returning promises:
bbrest.server().get();
bbrest.server().post('path.to.xml');
bbrest.server().put('path.to.xml');
portal()
Prepares request on portal domain. API Reference
- returns instance of the BBReq
Valid Requests, returning promises:
bbrest.portal().put('path.to.xml');
bbrest.portal().delete();
bbrest.portal().get();
bbrest.portal().rights().get();
bbrest.portal().rights().put('path.to.xml');
bbrest.portal().tags().get();
bbrest.portal().tags().post('path.to.xml');
bbrest.portal().tags('myTag').delete();
catalog(item)
Prepares request on server catalog. API Reference
- item - name of the item in server catalog
- returns instance of the BBReq
Valid Requests, returning promises:
bbrest.catalog().get();
bbrest.catalog().post('path.to.xml');
bbrest.catalog().put('path.to.xml');
bbrest.catalog().delete('path.to.xml');
bbrest.catalog('myItem').get();
bbrest.catalog('myItem').delete();
portalCatalog(item)
Prepares request on portal catalog. API Reference
- item - name of the item in porta catalog
- returns instance of the BBReq
Valid Requests, returning promises:
bbrest.portalCatalog().get();
bbrest.portalCatalog().post('path.to.xml');
bbrest.portalCatalog().put('path.to.xml');
bbrest.portalCatalog().delete('path.to.xml');
bbrest.portalCatalog('myItem').get();
bbrest.portalCatalog('myItem').delete();
page(name:String)
Prepares page request. API Reference
- name - name of the page to target
- returns instance of the BBReq
Valid Requests, returning promises:
bbrest.page().get();
bbrest.page().post('path.to.xml');
bbrest.page().put('path.to.xml');
bbrest.page('name').get();
bbrest.page('name').put('path.to.xml');
bbrest.page('name').delete();
bbrest.page('name').rights().get();
bbrest.page('name').rights().put('path.to.xml');
container(name:String)
Prepares container request. API Reference
- name - name of the container to target
- returns instance of the BBReq
Valid Requests, returning promises:
bbrest.container().get();
bbrest.container().post('path.to.xml');
bbrest.container().put('path.to.xml');
bbrest.container('name').get();
bbrest.container('name').put('path.to.xml');
bbrest.container('name').delete();
bbrest.container('name').rights().get();
bbrest.container('name').rights().put('path.to.xml');
widget(name:String)
Prepares widget request. API Reference
- name - name of the widget to target
- returns instance of the BBReq
Valid Requests, returning promises:
bbrest.widget().get();
bbrest.widget().post('path.to.xml');
bbrest.widget().put('path.to.xml');
bbrest.widget('name').get();
bbrest.widget('name').put('path.to.xml');
bbrest.widget('name').delete();
bbrest.widget('name').rights().get();
bbrest.widget('name').rights().put('path.to.xml');
link(name:String)
Prepares link request. API Reference
- name - name of the link to target
- returns instance of the BBReq
Valid Requests, returning promises:
bbrest.link().get();
bbrest.link().post('path.to.xml');
bbrest.link().put('path.to.xml');
bbrest.link('name').get();
bbrest.link('name').put('path.to.xml');
bbrest.link('name').delete();
bbrest.link('name').rights().get();
bbrest.link('name').rights().put('path.to.xml');
template(name:String)
Prepares template request. API Reference
- name - name of the template to target
- returns instance of the BBReq
Valid Requests, returning promises:
bbrest.template().get();
bbrest.template().post('path.to.xml');
bbrest.template('name').get();
bbrest.template('name').put('path.to.xml');
bbrest.template('name').rights().get();
bbrest.template('name').rights().put('path.to.xml');
user(name:String, showGroups:Boolean, groupName:String)
Prepares user request. API Reference
- name - name of the user to target
- showGroups - if true, user groups are targeted
- groupName - name of the group to delete user from
- returns instance of the BBReq
Valid Requests, returning promises:
bbrest.user().get();
bbrest.user().post('path.to.xml');
bbrest.user('user').get();
bbrest.user('user').put('path.to.xml');
bbrest.user('user').delete();
bbrest.user('user', true).get();
bbrest.user('user', true).post('path.to.xml');
bbrest.user('user', true, 'group').delete();
group(name:String, showUsers:Boolean)
Prepares group request. API Reference
- name - name of the group to target
- showUsers - if true, group's users are targeted
- returns instance of the BBReq
Valid Requests, returning promises:
bbrest.group().get();
bbrest.group().post('path.to.xml');
bbrest.group('group').get();
bbrest.group('group').put('path.to.xml');
bbrest.group('group').delete();
bbrest.group('group', true).get();
bbrest.group('group', true).post('path.to.xml');
bbrest.group('group', true, 'user').delete();
audit(meta:Boolean)
Prepares audit trails request. API Reference
- meta - if true, targets audit metadat, otherwise it targets audit events
- returns instance of the BBReq
Valid Requests, returning promises:
bbrest.audit().get();
bbrest.audit(true).get();
cache(type:String)
Prepares cache request. API Reference
- type - possible values: global, widget, chrome, closure, url, web, gmodel
- returns instance of the BBReq
Valid Requests, returning promises:
bbrest.cache('all').delete();
bbrest.cache('globalModelCache').delete();
bbrest.cache('retrievedWidgetCache').delete();
bbrest.cache('widgetChromeStaticCache').delete();
bbrest.cache('serverSideClosureCache').delete();
bbrest.cache('urlLevelCache').delete();
bbrest.cache('webCache').delete();
bbrest.cache('gModelCache').delete();
bbrest.cache('uuidFromExtendedItemNamesCache').delete();
bbrest.cache('springAclSidCacheRegion').delete();
bbrest.cache('contextNameToItemNameToUuidCache').delete();
bbrest.cache('widgetCache').delete();
bbrest.cache('uuidToContentReferencesCache').delete();
bbrest.cache('springAclCacheRegion').delete();
bbrest.cache('itemUuidToReferencingLinkUuidsCache').delete();
bbrest.cache('uuidToCacheKeysCache').delete();
bbrest.cache('versionBundleCache').delete();
You can get bookmarklet to delete all caches at once.
auto(data)
Performs POST or PUT request by finding the right BBRest method from the data.
- data - if string, represents path of the xml file which content will be sent. If object, it is first sent to config.plugin function
- returns promise with response value
Valid Request, returning promises:
bbrest.auto('path.to.xml');
import(filePath:String)
Imports portal. API Reference
- filePath - path to file to upload / import
- returns instance of the BBReq
Valid Requests, returning promises:
bbrest.import().post('path.to.xml');
bbrest.import('/path/to/exported.zip').post();
export(uuid:String)
Exports portal. API Reference
- uuid - id of the exported file on the server. Use when you need to download file
- returns instance of the BBReq
To get archive of the portal from the server, you need to make 2 requests.
In first one, we send type of export and get back the id of exported archive in response.
With second request we pass that id and local path where archive will be downloaded.
Valid Requests, returning promises:
bbrest.export().post('path.to.xml').then(data) {
var id = data.body.exportResponse.identifier;
bbrest.export(id).file('local.path.zip').get();
}
BBReq methods
rights()
Modifies request to target rights.
- returns instance of the BBReq
tag(name:String)
Modifies request to target tags
- returns instance of the BBReq
query(obj:Object)
Defines modifiers. API Reference
- obj - object with querystring values to be appended to the uri
- returns instance of the BBReq
file(path:String)
Defines path to the file where export is downloaded.
- returns instance of the BBReq
get()
Performs GET request
- returns promise with response value
post(data)
Performs POST request
- data - if string, represents path of the xml file which content will be sent. If object, it is first sent to config.plugin function
- returns promise with response value
bbrest.config.plugin = function(data) {
return jxon.jsToString(data);
}
bbrest.widget('myWidget').post(jxonObj);
put(data)
Performs PUT request
- data - if string, represents path of the xml file which content will be sent. If object, it is first sent to config.plugin function
- returns promise with response value
delete(data)
Performs DELETE request
- data - if string, represents path of the xml file which content will be sent. If object, it is first sent to config.plugin function
- returns promise with response value
response value:
{
error:
statusCode:
statusInfo:
body:
href:
method:
reqBody:
file:
headers:
}