我的数据模式看起来像
User
有很多 Transaction
。两者都是数据库User
中Transaction
的不同表
我有REST
端点
用户端点
GET /users/uuid # to get information about specific user
PUT /users/uuid # update information of a specific user
事务端点
GET /transactions/uuid # get a specific transaction
GET /transactions/user_uuid # get all transactions of a specific user
GET /transactions/user_uuid/yyyy # get all transactions of a specific user in year yyyy
GET /transactions/user_uuid/yyyy/mm # get all transactions of a specific user in year yyyy, month mm
GET /transactions/user_uuid/yyyy/mm/dd # get all transactions of a specific user in year yyyy, month mm and day dd
- 我的问题是,由于
transactions
将始终附加User
资源,因此为它们设置不同的端点是否有意义? - 推荐什么来访问用户的交易?上面贴的那个?或类似的东西
GET /users/uuid/transactions # all transactions for a user GET /users/uuid/transactions/yyyy # all transactions for a user for year yyyy GET /users/uuid/transactions/yyyy/mm # all transactions for a user for year yyyy, month mm GET /users/uuid/transactions/yyyy/mm/dd # all transactions for a user for year yyyy, month mm and day dd
我现在很困惑哪个更好。
谢谢