Skip to content

Instantly share code, notes, and snippets.

Created May 14, 2016 20:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/27becf1e370edcddcb5830afc064455e to your computer and use it in GitHub Desktop.
Save anonymous/27becf1e370edcddcb5830afc064455e to your computer and use it in GitHub Desktop.
Experimenting with Koajs and the Spotify api
'use strict'
const koa = require('koa')
const r = require('koa-route')
const https = require('https')
const app = koa()
app.use(r.get('/search/:term', function *(term) {
const req = https.request({
method: 'get',
protocol: 'https:',
host: 'api.spotify.com',
path: `/v1/search/q=${term}`
}, function *(res) {
console.log(`STATUS: ${res.statusCode}`);
console.log(`HEADERS: ${JSON.stringify(res.headers)}`);
res.end()
})
req.on('error', function *(e) {
console.error('error', e)
})
req.end()
}))
app.use(function *() {
this.body = 'Hello World'
})
app.listen(3000)
{
"name": "spotify",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"koa": "1.2.0",
"koa-route": "2.4.2"
},
"devDependencies": {
"babel": "6.5.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment