0

目前我只是在调用一个 API,特别是 Ticket Master Discovery API,它返回一个 JSON 对象就好了:

//PACKAGES 
var express = require('express');
var request = require('request'); 
var router = express.Router(); 


request('https://app.ticketmaster.com/discovery/v2/venues.json?keyword=UCV&apikey=' + apiKey, 
 function (error, response, body) {
  if (!error && response.statusCode == 200) {
    console.log(body);
    return;// Print the google web page.
  } 
    else {
      console.log(error); 
  }

});

我想利用 ExpressJS 的“获取”来响应获取请求,然后在其中进行“请求”调用(如上所示)——这可能还是我的理解不正确?我已经继续阅读文档,并以最简单的形式理解每个文档,但我仍在苦苦挣扎。

谢谢

4

1 回答 1

0

Here's a basic example:

const express = require('express');
const request = require('request');

const app = express();

app.get('/', function(req, res) {

    request('https://app.ticketmaster.com/discovery/v2/venues.json?keyword=UCV&apikey=' + apiKey, function (error, response, body) {
        if (!error && response.statusCode == 200) {
            res.send(body);
        } 
        else {
            res.send(error);
        }
    });

})

app.listen(3000, function() {
    console.log('Server listening on 3000');
})

If you run this code and then browse to http://localhost:3000/ then you should see the ticketmaster.com response.

于 2017-05-30T14:10:35.777 回答