-
-
Save shrunyan/aec0bc95a0050bf8106989f58c0aae8e to your computer and use it in GitHub Desktop.
Experimenting with Koajs and the Spotify 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
'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) |
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
{ | |
"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