Last active
October 18, 2018 23:55
-
-
Save brianium/65ccc8651d0b0fb5fce2 to your computer and use it in GitHub Desktop.
Koa.js X-MEN Api
This file contains hidden or 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 = 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