-
Notifications
You must be signed in to change notification settings - Fork 2
/
wordnik.js
31 lines (23 loc) · 908 Bytes
/
wordnik.js
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
31
var http = require('http');
var request = require('request');
var searchWord = "cat";
//Lets try to make a HTTPS GET request to the wordnik API.
function wnRequest(searchTerm, callback) {
var wordnikurl = "http://api.wordnik.com:80/v4/word.json/" + searchTerm + "/definitions?limit=200&includeRelated=true&useCanonical=false&includeTags=false&api_key=83916c7411db7255406860c49b9083f65a950aff27e3c6a5d";
request.get(wordnikurl, function(error, response, body) {
if (error) {
return;
}
if (response.statusCode !== 200) {
return;
} else {
var object = JSON.parse(body);
if (!object[0]) {
callback('Sorry, this word is too obscure for the wordnik API... Please try again.');
} else {
callback(object[0].text);
}
}
});
}
module.exports = wnRequest;