Skip to content

Repository files navigation

@oada/client

npmDownloads/weekcode style: prettierLicense

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

import{connect}from'@oada/client';constconnection=awaitconnect({domain: 'api.oada.com',// domain of OADA servertoken: 'abc',// token});

GET

Single GET

constresponse=awaitconnection.get({path: '/bookmarks/test',timeout: 1000,// timeout in milliseconds (optional)});

Recursive GET

constdataTree={bookmarks: {_type: 'application/vnd.oada.bookmarks.1+json',_rev: 0,thing: {_type: 'application/json',_rev: 0,abc: {'*': {_type: 'application/json',_rev: 0,},},},},};constresponse=awaitconnection.get({path: '/bookmarks/thing',tree: dataTree,timeout: 1000,// timeout in milliseconds (optional)});

Watch

A watch request can be issued by sending a watch request as follows.

// Resolves once the watch is establishedconst{ changes }=awaitconnection.watch({path: '/bookmarks/test',rev: 1,// optionaltimeout: 1000,// timeout in milliseconds (optional)});// Async iterator for all changes since the watch was started (or since `rev`)forawait(constchangeofchanges){console.log(change);}

You can also GET the current state of the resource when establishing a watch as follows.

// Resolves once the watch is establishedconst{ data, changes }=awaitconnection.watch({initialMethod: 'get',path: '/bookmarks/test',});// Current body of the resourceconsole.dir(data);// Async iterator for all changes since the watch was startedforawait(constchangeofchanges){console.log(change);}

PUT

Single PUT

constresponse=awaitconnection.put({path: '/bookmarks/test',data: {thing: 'abc'},contentType: 'application/json',timeout: 1000,// timeout in milliseconds (optional)});

Tree PUT

constdataTree={bookmarks: {_type: 'application/vnd.oada.bookmarks.1+json',_rev: 0,thing: {_type: 'application/json',_rev: 0,abc: {'*': {_type: 'application/json',_rev: 0,},},},},};constresponse=awaitconnection.put({path: '/bookmarks/thing/abc/xyz/zzz',tree: dataTree,data: {test: 'something'},timeout: 1000,// timeout in milliseconds (optional)});

HEAD

constresponse=awaitconnection.head({path: '/bookmarks/test',timeout: 1000,// timeout in milliseconds (optional)});

About

A lightweight client tool for interacting with an OADA-compliant server

Topics

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages