@oada/client
A lightweight client tool for interacting with an OADA-compliant server
Installation
This module is available through npm. To install the module, simply run:
$ npm install @oada/client
Usage
Connect
const client = require('@oada/client');
const connection = await client.connect({
domain: 'api.oada.com',
token: 'abc',
});
GET
Single GET
const response = await connection.get({
path: '/bookmarks/test',
timeout: 1000,
});
Recursive GET
const dataTree = {
bookmarks: {
_type: 'application/vnd.oada.bookmarks.1+json',
_rev: 0,
thing: {
_type: 'application/json',
_rev: 0,
abc: {
'*': {
_type: 'application/json',
_rev: 0,
},
},
},
},
};
const response = await connection.get({
path: '/bookmarks/thing',
tree: dataTree,
timeout: 1000,
});
Watch
A watch request can be issued by sending a watch
request as follows.
const { changes } = await connection.watch({
path: '/bookmarks/test',
rev: 1,
timeout: 1000,
});
for await (const change of changes) {
console.log(change);
}
To unwatch a resource, use the unwatch
request.
const response = await connection.unwatch(requestId);
PUT
Single PUT
const response = await connection.put({
path: '/bookmarks/test',
data: { thing: 'abc' },
contentType: 'application/json',
timeout: 1000,
});
Tree PUT
const dataTree = {
bookmarks: {
_type: 'application/vnd.oada.bookmarks.1+json',
_rev: 0,
thing: {
_type: 'application/json',
_rev: 0,
abc: {
'*': {
_type: 'application/json',
_rev: 0,
},
},
},
},
};
const response = await connection.put({
path: '/bookmarks/thing/abc/xyz/zzz',
tree: dataTree,
data: { test: 'something' },
timeout: 1000,
});
HEAD
const response = await connection.head({
path: '/bookmarks/test',
timeout: 1000,
});