【发布时间】:2019-01-15 14:32:16
【问题描述】:
你好,一月快乐!
回顾我最近创建的一个非常简单的 RESTful API,我想知道我是否为它的 POST 做了 RESTful API 签名。
这个 RESTful API 查询一个非常简单的 MongoDB 集合Apps,它的列是:
-
_id, (appId) -
siteId(必填) -
accountId(必填) -
provider(必填) description
索引:
-
provider,siteId,accountId:unique
数据结构:
- 每个站点 (
siteId) 都有多个帐户 (accountId)。 - 每个帐户 (
accountId) 都有多个应用 (appId)。
HTTP动词GETDELETE和PATCH处理集合Apps中项目的路径是:
-
GET /api/v1/sites/:siteId/accounts/:accountId/apps -
DELETE /api/v1/sites/:siteId/accounts/:accountId/apps PATCH /api/v1/sites/:siteId/accounts/:accountId/apps
我的困惑如下:我想POST 一个将与siteId + accountId 关联的新应用程序。
我想知道我如何定义这个POST 路径是否有意义,因为新应用程序可能是第一次将siteId 或accountId 添加到此集合中。
这是我为 HTTP 动词 POST 实现的:
POST /api/v1/sites/:siteId/accounts/:accountId/apps
params: {
siteId: string,
accountId: string,
},
body: {
provider: '[** Provider **]',
description: '[** Description **]',
siteId: '[** Site ID **]',
accountId: '[** Account ID **]'
},
response: new `appId`
或者应该是(我开始倾向于):
POST /api/v1/apps
body: {
provider: '[** Provider **]',
description: '[** Description **]',
siteId: '[** Site ID **]',
accountId: '[** Account ID **]'
},
response: new `appId`
真的欢迎推荐!
【问题讨论】:
标签: rest restful-url