ranm8 / requestify

Simplifies node HTTP request making.
http://ranm8.github.io/requestify
MIT License
223 stars 55 forks source link

Doesn't work... I never get a response. Am I doing something wrong? #41

Open jamesmgg opened 8 years ago

jamesmgg commented 8 years ago
// using node v4.2.1
// express 4.13.3
// requestify 0.2.0

var express = require('express');
var app = express();
var requestify = require('requestify');

app.get('/api/get-recommendations', function (req, res) {
  requestify.get(MY_URL)
  .then(function(response) {
      console.log(response.getCode())
      res.send(response)
      // response.getBody();
  });
})

var server = app.listen(3001, function () {
  var host = server.address().address;
  var port = server.address().port;
});
fredrikwidlund commented 8 years ago

Same here. In the console i get a {state: 'pending'} message, but I'm not able to get the 'then' function to run.

jamesmgg commented 8 years ago

I ended up using superagent. Works like a charm.

angelxmoreno commented 8 years ago

One thing you might do better is always catch your promises.

requestify.get(MY_URL).then(function(response) {
    console.log(response.getCode())
    res.send(response)
    // response.getBody();
}).catch(function(err){
    console.log('Requestify Error', err);
    next(err);
});

This will allow you to capture the error from the promise.

alshakero commented 8 years ago

requestify automatically sets Content-Type to JSON. Make sure to change that.