首页 > 解决方案 > NodeJS Express 递归路由

问题描述

某些网站的 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

而不是

            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

另一个例子虽然我不确定 Github 是否允许这样做

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

你将如何在快递中实现这样的事情?

标签: javascriptnode.jsrestexpress

解决方案



推荐阅读