Johannes
Johannes

Reputation: 13

Trying to send JSON response with Restify

I am trying to list all jobs with a certain tag on angel.co using their API with the current call

https://api.angel.co/1/tags/10/startups

and then trying to parse it and show in the browser using restify

var tagUrl = "https://api.angel.co/1/tags/10/startups"
    request({
        url: tagUrl,
        json: true
    }, function (error, response, body) {

        if (!error && response.statusCode === 200) {
           console.log(body) // Print the json response
        }
        else console.log("error" + error)
    })

I'm getting the console.log(body)-part to work, but when I am trying to send the response to the browser it doesn't show anything when I am trying to send it with

res.send('hello ' + req.params.name + body);

Should I parse or stringify it in some way ?

edit: This is the final code

function respond(req, res, next) {
var tag = req.params.tag;
var url = "http://api.angel.co/1/tags/"+tag+"/startups/?


request({
     url: url,
    json: true
}, function (error, response, body) {

if (!error && response.statusCode === 200) {
    console.log(body) // Print the json response
    res.send( req.params.name + JSON.stringify(body));

}
else console.log("error" + error)
})

Upvotes: 1

Views: 1654

Answers (1)

vivek
vivek

Reputation: 71

Use stringify property of json,which converts the json format to string

JSON.stringify(body)

Upvotes: 1

Related Questions