正如你可以在下面看到的,在我的server.js文件中,我有一個/ POST信息請求被調用表單提交。Axios請求內/快速POST請求
我開始對閱讀app.post和express路線之間的差異感到困惑,如果無論如何使用路線會使我的代碼在這裏受益。
在/ POST信息中我對兩個不同的API有兩個axios請求,我認爲將代碼移到其他地方是明智的做法,以使其更清潔。
會知道路線在這裏工作對我有什麼好處嗎?如果你能解釋這裏的差異,那將是很棒的。
app.post('/Info', function (req, res) {
var State = req.body.State;
var income = Number(req.body.income);
var zip = req.body.ZIP;
axios.post('https://taxee.io/api/v2/calculate/2017', {
//data sent to Taxee.io
"exemptions": 1
, "filing_status": "single"
, "pay_periods": 1
, "pay_rate": income || 100000
, "state": State || "NY"
}, {
headers: {
'Authorization': "Bearer <API_KEY>"
//headers
}
}).then(function (response) {
var obj = {
income: '$' + income
, fica: response.data.annual.fica.amount
, federal: response.data.annual.federal.amount
, residence: State + ", " + zip
, state: response.data.annual.state.amount
}
axios.get("https://www.quandl.com/api/v3/datasets/ZILL/Z" + zip + "_RMP.json?api_key=<API_KEY>").then(function (response) {
var monthRent = response.data.dataset.data[0][1]
obj.rent = monthRent
obj.yearlyRent = Number(monthRent) * 12;
}).then(function (response) {
res.send(obj);
});
}).catch(function (error) {
alert('error');
});
}
http.get({ 主機名: '本地主機', 端口:80, 路徑: '/', 劑:假//創建一個新的代理只爲這一個請求 },(RES)=> { //做任何事情與迴應 });這種沒有代理的東西? – Aaron