【发布时间】:2015-02-18 04:43:36
【问题描述】:
我正在尝试使用当前调用的 API 在 angel.co 上列出所有带有特定标签的工作
https://api.angel.co/1/tags/10/startups
然后尝试解析它并使用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)
})
我正在让 console.log(body)-part 工作,但是当我尝试将响应发送到浏览器时,当我尝试使用
发送它时它没有显示任何内容res.send('hello ' + req.params.name + body);
我应该以某种方式对其进行解析或字符串化吗?
编辑:这是最终代码
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)
})
【问题讨论】:
-
不,我在服务器端使用 node.js,它获取并解析 URL。然后我使用 res.send 方法将其呈现给访问某个 URL 的用户
标签: javascript json node.js restify