-
-
Save JorgeMadson/03e5b5c4fe775d93a967b2bc1aa63061 to your computer and use it in GitHub Desktop.
Koa.js X-MEN Api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var koa = require('koa'); | |
var app = new 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