I have 2 existing endpoints /balance /transactions
What is the best way to create a new one /balance-and-transactions
and not rewrite existing code For instance:
a('/balance', () => {
foo()
res.send({ /*some json with balance */ });
});
b('/transactions',() => {
boo();
res.send({ /*some json with transactions */ });
});
newendpoint('/balance-and-transactions', () => {
foo();
boo();
res.send({ /*some combined json with balance and transactions altogether */ });
});
Is it a good idea to call 2 requests inside newendpoint (internal call)?
newendpoint('/balance-and-transactions', () => {
data1 = request('/balance');
data2 = request('/transactions');
// then combine data1 and data2
res.send({ /*some combined json with balance and transactions altogether */ });
});
合并这些端点不是一个好主意,但是如果您仍然想要这样做,最好使用破折号而不是下划线/balance-and-names
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.