medmond919

Single API Client

Apr 20th, 2016
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. var request = require('request');
  2.  
  3.  
  4. //Read the API Key
  5. ...
  6. }
  7.  
  8.  
  9. function getSyn(word, callback) {
  10. var options = {
  11. uri : ' http://words.exampleapi.com/api/2/' + config.apiKey + '/' + blah blah + '/json ',
  12. method : 'GET'
  13. };
  14. var res = '';
  15. request(options, function (error, response, body) {
  16. if (!error && response.statusCode == 200) {
  17. res = body;
  18. }
  19. else {
  20. res = 'Not Found';
  21. }
  22. callback(res);
  23. });
  24. }
  25.  
  26.  
  27.  
  28. getSyn("motivation", function(resp){
  29.  
  30. var parsed = JSON.parse(resp);
  31. console.log(parsed.noun.syn[0]);
  32. console.log(parsed);
  33. });
Advertisement
Add Comment
Please, Sign In to add comment