Mixin: superagent

superagent

This mixin provides [ajax()]KagoDB#ajax method to perfome Ajax with superagent module. This would be also useful when testing your webapi using supertest module, as it contains superagent. Web browser build of superagent is also available.
Source:
See:

Examples

var MyKago = KagoDB.inherit();
MyKago.mixin(KagoDB.bundle.superagent());
var collection = new MyKago();

var options = {
  method: 'GET',
  url: 'http://graph.facebook.com/4',
};
collection.ajax(options, function(err, body) {
  console.log(body); // JSON
});
var opts = {
  storage: 'http_superagent',
  endpoint: 'http://localhost:3000/data/'
};

var collection = new KagoDB(opts);

collection.read('foo', function(err, item){
  // http://localhost:3000/data/foo
});
var express = require('express');
var supertest = require('supertest');

var app = express();
var server_opts = {
  storage: 'memory'
};
app.all('/data/:id?', KagoDB(server_opts).webapi());

var client_opts = {
  storage: 'http_superagent',
  endpoint: '/data/',
  superagent: supertest(app)
};

var collection = new KagoDB(client_opts);
var item = {
  bar: 'buz'
};
collection.write('foo', item, function(err) {
  collection.read('foo', function(err, item) {
    console.log(item); // => { bar: 'buz' }
  });
});