Giter VIP home page Giter VIP logo

node-basex's Introduction

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

node-basex's People

Contributors

nerdenough avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.