Skip to content

Instantly share code, notes, and snippets.

@brianium
Last active October 18, 2018 23:55
Show Gist options
  • Save brianium/65ccc8651d0b0fb5fce2 to your computer and use it in GitHub Desktop.
Save brianium/65ccc8651d0b0fb5fce2 to your computer and use it in GitHub Desktop.
Koa.js X-MEN Api
var koa = require('koa');
var app = koa();
var json = require('koa-json');
app.use(json());
app.use(function* (next) {
if (this.method != 'GET') return yield next;
if (!/x-men/.test(this.originalUrl)) return yield next;
this.body = {
results: [
{
name: "Wolverine",
power: "Sharp things"
},
{
name: "Cyclops",
power: "Laz0r eyes"
},
{
name: "Prefessor Xavier",
power: "Mind laz0rz"
}
]
}
});
app.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment