0.0.3 • Published 8 years ago

node-basex v0.0.3

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

BaseX REST Client

Build Status

BaseX REST Client provides an easy way to query a BaseX (XML Database) HTTP server through its REST API using the POST method.

Getting Started

Installation

$ npm install node-basex

Usage

var basex = require('node-basex');

var client = new basex.Client({});
var query = {
  text: 'for $i in //example return $i'
};

client.query(query, function (data) {
  console.log(data); // Response data
});

In Depth

The BaseX REST API documentation contains information on how a POST query should be structured for communicating with Basex and will help clarify the various options specified below.

Creating the REST Client

The BaseX REST Client is created by providing an object containing all the options for the connection. The options are option and include host, port, path, username, and password. Any option omitted will use the default BaseX value.

var basex = require('node-basex');
var client = new basex.Client({
  host: 'localhost',
  port: 8984,
  path: '/rest/mydatabase',
  username: 'admin',
  password: 'admin'
});

Note: An empty object is required for the options even if you are using defaults

Queries

Queries follow the BaseX REST POST Schema and can consist of text, context, parameter, variable and option elements.

Text

The text element is used to specify the query operation.

var query = {
  text: 'for $i in //example return $i'
};

Context

The context parameter is used to provide an initial XML context node.

var query = {
  context: 'context'
};

Options

Options are applied before the actual query operation (text) is performed.

var query = {
  options: [
    {key: 'option1', value: 1},
    {key: 'option2', value: 2}
  ]
};

Variables

Variables allow for external variables to be set that can be referenced from the text element.

var query = {
  variables: [
    {key: 'var1', value: 1},
    {key: 'var2', value: 2}
  ]
};

Running the Query

When the query is run, any response data will be returned via the callback so long as the BaseX HTTP server is running.

client.query(query, function (data) {
  // Response data can be null
});

Running Tests

$ npm install -g gulp mocha
$ npm test
0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago