Is there a way to declare multiple API routes from a single file in Arrow?
Example: Say you want to declare multiple endpoints for a user API:
It would make sense to keep these in the same file since they are related and could share code, instead of splitting them into their own files.
I'm referring to these docs .
At this moment the only way to keep them in the same file is to use ALL
as the method and then in the action use req.method
to delegate to the right logic. Eg:
..
method: 'ALL',
action: function(req, res, next) {
switch (req.method) {
case 'GET':
..
break;
case 'DELETE':
..
break;
default:
return res.notfound(next);
break;
}
}
..
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.