以典型的REST方式,我有一个名为/users
的资源,具有以下方法:
POST
创建用户GET
获取所有用户然后,当客户指定他们想要与/users/{userId}
进行交互的用户ID时,它允许他们使用以下方法:
GET
获取指定的单个用户PUT
更新指定的用户DELETE
删除指定的用户我遇到的问题是,API蓝图将它们分别分组在一起,因为它们在技术上是不同的资源,即使我将它们视为同一类别。
有没有一种方法可以将它们归为一组,或者有比我正在做的更好的方法来组织这种结构?
如果需要更多上下文,请参见以下代码示例:
# Group Users
## Users [/users]
Register a new user.
### Create new user [POST]
+ Request (application/json)
+ Body
{
"firstName": "Leslie",
"lastName": "Knope",
"email": "leslieknope@pawnee.gov",
"password": "jjsdiner"
}
+ Response 201 (application/json)
{
"status": "success",
"message": "User created",
"payload": {
"user": {
"id": 10,
"firstName": "Leslie",
"lastName": "Knope",
"email": "leslieknope@pawnee.gov"
}
}
}
### List users [GET]
+ Request (application/json)
+ Headers
Access-Token: accessToken
+ Response 200 (application/json)
{
"status": "success",
"message": "User created",
"payload": {
"users": [
{
"id": 10,
"firstName": "Leslie",
"lastName": "Knope",
"email": "leslieknope@pawnee.gov"
}
]
}
}
## Single User [/users/{userId}]
### Read user [GET]
+ Parameters
+ userId (required, integer, `10`) ... User id to fetch
+ Request (application/json)
+ Headers
Access-Token: accessToken
+ Response 200 (application/json)
{
"status": "success",
"message": "Single user",
"payload": {
"user": {
"id": 10,
"firstName": "Leslie",
"lastName": "Knope",
"email": "leslieknope@pawnee.gov"
}
}
}
### Update user [PUT]
+ Parameters
+ userId (required, integer, `10`) ... User id to fetch
+ Request (application/json)
+ Headers
Access-Token: accessToken
+ Body
{
"lastName": "Wyatt",
}
+ Response 201 (application/json)
{
"status": "success",
"message": "User updated",
"payload": {
"user": {
"id": 10,
"firstName": "Leslie",
"lastName": "Wyatt",
"email": "leslieknope@pawnee.gov",
}
}
}
### Delete user [DELETE]
Remove a user and their related data. This action will trigger the removal of all budgets, favorites, award letters, and the user itself permanently.
+ Response 204 (application/json)