# ak-rest

> minimalistic Akiban REST driver for node.js

Latest version **0.0.1** (published 2013-04-12) · 0 weekly downloads

## Install

```sh
npm install ak-rest
pnpm add ak-rest
yarn add ak-rest
bun add ak-rest
```

## Health

**Score 10/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2013-04-12 |
| First published | 2013-04-12 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+4 in 2 direct dependencies) |
| Install scripts | no |
| Author | Akiban Technologies |
| Maintainers | posulliv |

## Links

- npm: https://www.npmjs.com/package/ak-rest
- Repository: http://github.com/akiban/node-akiban-rest
- Issues: http://github.com/akiban/node-akiban-rest/issues
- npm.io page: https://npm.io/package/ak-rest

## Dependencies (3)

- [errs](https://npm.io/package/errs.md) 0.2.x
- [request](https://npm.io/package/request.md) 2.16.x
- [underscore](https://npm.io/package/underscore.md) 1.4.x

## Recent versions

- 0.0.1 (latest) — 2013-04-12

## README

# Akiban REST Client for Node.js

A minimalistic Akiban client for node.js inspired by the
[nano][nano_link] driver for couchdb.

## Installation

1. install [npm][npm_link]
2. `npm install ak-rest`

## Getting Started

To connect to Akiban:

``` js
var akiban = require('ak-rest')('http://localhost:8091/v1');
```

In `node-rest-akiban` the callback function receives always three arguments:

* `err` - the error, if any
* `body` - the http _response body_ from Akiban, if no error. 
* `header` - the http _response header_ from Akiban, if no error

A simple but complete example using callbacks is:

``` js
var akiban = require('ak-rest')('http://localhost:8091/v1');

// create a new model based on a JSON doc
model_doc = { "name" : "padraig" }
akiban.model.create('padraig', model_doc, function(err, header, body) {
  if (err) {
    console.log(err);
  } else {
    console.log(header);
    console.log(body);
  }
});
```

If you run this example(after starting Akiban) you will see:

```
{ 'content-type': 'application/json',
  'transfer-encoding': 'chunked',
  'status-code': 200,
  uri: 'http://localhost:8091/v1/model/parse/test.padraig?create=true' }
{ entities: 
   { padraig: 
      { entity: 'd6928c9b-168c-46df-ba3e-2a466acac221',
        attributes: [Object] } } }
```

## Model Functions

### model.create(name, json_doc, [callback])

Create a model called `name` from a JSON document and instantiate it.

``` js
json_doc = { "id": 657, "value": "this is some data" }
akiban.mode.create('t1', json_doc, function(err, body) {
  if (!err) {
    console.log(body);
  }
});
```

## Entity Functions

### entity.create(name, json_doc, [callback])

Create a new instance of the `name` entity from `json_doc`.

``` js
entity_json = { "id": 54, "value": "this is some data" }
akiban.entity.create('t1', entity_json, function(err, body) {
  if (!err) {
    console.log(body);
  }
});
```

### entity.get(name, id, [callback])

Retrieve a single instance of the entity called `name` whose identifier
is `id`.

``` js
akiban.entity.get('t1', 54, function(err, body) {
  if (!err) {
    console.log(body);
  }
});
```

### entity.destroy(name, id, [callback])

Destroy a single instance of the entity called `name` whose identifier
is `id`. Successful response has an empty body.

``` js
akiban.entity.destroy('t1', 54, function(err, headers) {
  if (!err) {
    console.log(headers);
  }
});
```

### entity.replace(name, id, [callback])

Replace the entire instance of the entity called `name` whose identifier
is `id`.

``` js
akiban.entity.replace('t1', 54, function(err, body) {
  if (!err) {
    console.log(body);
  }
});
```

## SQL Functions

### sql.execute(query, [callback])

Execute a single SQL query.

``` js
akiban.sql.execute('select * from  t1', function(err, body) {
  if (!err) {
    console.log(body);
  }
});
```

### sql.explain(query, [callback])

Generate an execution plan for a single SQL query.

``` js
akiban.sql.explain('select * from  t1', function(err, body) {
  if (!err) {
    console.log(body);
  }
});
```

### sql.multi(queries, [callback])

Execute multiple SQL statements within a single transaction. Individual
statements can be free-form and must be separated by semicolons (;).

``` js
queries = 'select * from t1; select max(id) from t1;';
akiban.sql.multi(queries, function(err, body) {
  if (!err) {
    console.log(body);
  }
});
```

## Full Text Functions

### ft.search(entity_name, index_name, query, [callback])

Perform a full text search on the specified index.

``` js
akiban.ft.search('t1', 'ft_idx', 'value:dream', function(err, body) {
  if (!err) {
    console.log(body);
  }
});
```

### ft.rebuild(entity_name, index_name, [callback])

Rebuild the given index.

``` js
akiban.ft.rebuild('t1', 'ft_idx', function(err, body) {
  if (!err) {
    console.log(body);
  }
});
```

[nano_link]: http://github.com/dscape/nano
[npm_link]: http://npmjs.org

---
_Source: https://npm.io/package/ak-rest · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
