Last active
June 28, 2016 03:53
-
-
Save f0rr0/16064533a7f761d4eb9488fc4a2465c4 to your computer and use it in GitHub Desktop.
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
import get from './pokemondb'; | |
import stats from './stats'; | |
import Koa from 'koa'; | |
import route from 'koa-route'; | |
import logger from 'koa-logger'; | |
const getPokemonFromAPI = async (ctx, name) => { | |
try { | |
const data = await get(name); | |
ctx.body = stats(data); | |
} catch (err) { | |
ctx.throw(404, err.error.detail); | |
} | |
}; | |
const app = new Koa(); | |
app.use(logger()) | |
.use(route.get('/:name', getPokemonFromAPI)) | |
.listen(8000); | |
console.log('Listening on Port 8000'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment