koa-undo
Enable undo feature for all the http request.
Last updated 2 years ago by sweetvvck .
MIT · Repository · Bugs · Original npm · Tarball
$ cnpm install koa-undo 
SYNC missed versions from official npm registry.

NPM

koa-undo

Add undo capability for api.

Installation

$ npm install koa-undo

Example

Use koa-undo:

var koa = require('koa');
var undo = require('koa-undo');
var route = require('koa-route');
var formidable = require('koa-formidable');

var app = koa();
// use koa-undo
app.use(formidable({
  uploadDir: path.join(__dirname, '/tmp/')
}));
app.use(undo({expired: 500, apis: ['/resource']}));

// require auth

app.use(route.post('/resource', function *(next){
  resource = this.request.body.resource;
  this.body = 'ok';
  yield next;
}));

app.listen(3000);
console.log('listening on port 3000');

Example request:

var request = require('superagent');

request
.post('http://localhost:3000/resource')
.set('X-IDENTIFY-KEY', '123')
.send({resource: true})
.end(function (err, res){
  if (err) { console.error(err); }
});

request
.post('http://localhost:3000/undo')
.set('X-IDENTIFY-KEY', '123')
.send({})
.end(function (err, res) {
  if (err) { console.error(err); }
});

Running test

Install dependencies:

$ npm install

Start test:

$ npm test

License

MIT

Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (5)
Dependents (1)

Copyright 2014 - 2017 © taobao.org |