我有兩個端點:Koa2同一路線不同PARAMS
通過ID得到所有用戶
http.get(API_URL + "users/" + id)
GET通過用戶名的所有用戶
http.get(API_URL + "users/" + username)
我可以發送不同的參數在同一條路線上:
router.get("https://stackoverflow.com/users/:id", async ctx => {
//ctx.request.param is id
//do something
});
router.get("https://stackoverflow.com/users/:username", async ctx => {
//ctx.request.param is username
//do something
});
感謝您的幫助!