-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexternalApi.js
More file actions
30 lines (27 loc) · 946 Bytes
/
externalApi.js
File metadata and controls
30 lines (27 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
'use strict';
const request = require('request');
const API_URL = 'https://fourtytwowords.herokuapp.com/';
const API_KEY = '1ce8673914f5f154b52e96bdf84c7bac9d16ad3dbcd4824d6842320ca41983252c8226fef084b6cf6ff9511ce37fba95bac5c115af23695d0d32e81f70debdb3bb61c89c19dba960720269d67e7c3410';
const externalApi = {
hitApi: function (api, word = '') {
let url = API_URL;
if (api == 'random') {
url += 'words/randomWord';
} else {
url += 'word/' + word + '/' + api;
}
var options = {
method: 'GET',
url: url,
qs: {api_key: API_KEY},
form: false
};
return new Promise(function (resolve, reject) {
request(options, function (error, response, body) {
if (error) throw new Error(error);
resolve(JSON.parse(body));
});
});
}
}
module.exports = externalApi;