简体   繁体   English

NodeJS Express 递归路由

[英]NodeJS Express recursive routes

Some website's APIs let you do something like this:一些网站的 API 可以让你做这样的事情:

            Initial user's id          their first friend, also a user
                 v                     v
GET /api/users/54282/friends/0/friends/0
                             ^
                        first item in array, would also be a user

Rather than而不是

            Initial user's id
                 v
GET /api/users/54282/friends
Look at friends[0].id to get the first friend's id

            First friend's id
                 v
GET /api/users/97420/friends
Look at friends[0].id to get the first friend's id

            First friend's id
                 v
GET /api/users/31230

Another example although i'm not sure if Github allows this另一个例子虽然我不确定 Github 是否允许这个

Get the 10th collaborator's repos
GET /api/users/sharedrory/repos/312388/collaborators/10/repos

How do would you implement something like this in express?你会如何在 express 中实现这样的东西?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM