Node module providing promisified API to interact with eXist-db's REST API.
var exist = require('easy-exist');
// connect
var db = new exist.DB('http://localhost', {
username: "test-user",
password: "password"
});
body = '<message><body>Hello World</body></message>'
// PUT a document
db.put('/my-collection/my-document', body)
// Get the body of a document
.then(function() {
return db.get('/my-collection/my-document');
})
.then(function(doc) {
console.log('Document Body:', doc);
})
// Execute xQuery
.then(function() {
return db.query('collection("my-collection")/message/body');
})
.then(function(result) {
console.log('xQuery result:', result);
})
// Delete document
.then(function() {
return db.delete('/my-collection/my-document');
})
.then(function() {
console.log('Document Deleted');
});
Install via NPM
npm install easy-exist --save
Then require
var exist = require('easy-exist');
-
url
- string -
options
- object - configuration options
The options
object supports the following properties:
-
username
- string - Username for HTTP Basic Auth -
password
- string - Password for HTTP Basic Auth -
collection
- string - Name of collection under which all subsequent requests will apply to
Stores an XML document at the given URI.
-
uri
- string - the URI at which to store the given body -
body
- string - the document body
A request-promise Promise. If a non-2xx response is returned, the promise is rejected.
Retrieves the body of the document at the given URI.
-
uri
- string - the URI of the document to fetch
A request-promise Promise. If a non-2xx response is returned, the promise is rejected, otherwise it is resolved with the body of the specified document.
Deletes the document at the given URI.
-
uri
- string - the URI of the document to delete
A request-promise Promise. If a non-2xx response is returned, the promise is rejected.
Executes given query against store and returns result
-
query
- string - xQuery to execute agains the store -
options
- object - Query options
The options
object supports the following properties:
-
start
- integer - Specifies the index position of the first item in the result sequence to be returned. The default value is 1 -
max
- integer - The maximum number of items to be returned -
wrap
- string - (yes
|no
) - Specifies whether the returned query results are to be wrapped into a surrounding exist:result element. The default value is yes
A request-promise Promise. If a non-2xx response is returned, the promise is rejected, otherwise it is resolved with the xQuery result.
Stores the given xQuery at the specified URI
-
uri
- string - the URI at which to store the given xQuery -
query
- string - the xQuery body
A request-promise Promise. If a non-2xx response is returned, the promise is rejected.
Executes the xQuery stored at the given URI and returns the results.
Syntactic Sugar. This function simply calls through to .get(uri)
-
uri
- string - the URI of the xQuery to execute
A request-promise Promise. If a non-2xx response is returned, the promise is rejected, otherwise it is resolved with the result of executing the specified specified xQuery.
Determines if a document exists at the given URI
-
uri
- string - the URI of the document to check
A Promise. Resolves with true
if a document exists at the given uri, false
if it does not. If a non 2xx and non 404 status code is returned, the promise is rejected.
- Fork the project.
- Create your branch
- Make your changes with tests
- Run tests:
grunt test
- Run hint:
grunt hint
- Run tests:
- Create a Pull Request
The tests run against a local exist-db instance under a "test-user" account. If you want to run the tests yourself, ensure that this test-user account has been created. You can update the connection properties in spec/lib/db-spec.js
var DB_HOST = 'http://localhost';
// ...
var db = new DB(DB_HOST, { username: 'test-user', password: 'password'} );