1
0
Fork 0
oh-i-use/oh-i-use-backend.js
2016-10-06 16:08:54 -05:00

21 lines
558 B
JavaScript

'use latest';
require('isomorphic-fetch');
module.exports = function(ctx, done) {
if (!ctx.data.word) {
done(null, 'Please supply a word');
return;
}
fetch(`https://wordsapiv1.p.mashape.com/words/${ctx.data.word}/hasTypes`, {
method: 'GET',
mode: 'cors',
headers: {
'Accepts': 'application/json',
'X-Mashape-Key': 'C7TVYyPI9Fmsh61STvYMLm8opXXgp1JB6NOjsn3Tdw5PRqjaTj'
}
})
.then(r => r.json())
.then(r => done(null, r)) // Return content to the user
.catch(e => done(null, e.error));
};