[英]How to RESTfully support the creation of a resource which is a collection of other resources and avoiding HTTP timeouts due to DB creation?
[英]How to put resource creation and other methods in the same group?
假設我使用POST /resource
創建了一個資源,並且在響應主體上生成了一個id
,然后使用該id
通過GET /resource/{id}
來檢索我的資源。
如何將這兩個請求放在同一個API藍圖組中?
顯然,一個組只有一個端點,這使您看起來像您將使用POST /resource/{id}
創建資源的情況不一樣,因為此時您甚至沒有id。
## Resource [/resource/{id}]
### Creating the resource [POST]
+ Response 201
+ Body
{
"id": "uuid"
}
### Retrieving the resource [GET]
+ Parameters
+ name (string) ... The name of your collection.
+ Response 200
+ Body
{
"id": "uuid"
}
我查看了示例,但是找不到創建和檢索特定資源的示例。 我做錯了嗎?
從技術上講/resource
和/resource/123456
是不同的資源標識符。 有關更多詳細信息,請參閱HTTP資源比您想象的要簡單得多 。
就我個人而言,我更喜歡將其視為“資源”和“資源集合”。 創建操作通常意味着“創建並插入到集合中”。 集合具有一個URL(例如/mighty/frogs/in/the/wood/
或/resources
),集合中的資源具有另一個URL(例如/123124
或/resources/1234
)注意,這是絕對的URL的值只要是唯一的就無關緊要-據說,擁有健全的URL通常是一個好主意。
返回藍圖:
# Collection of Resource [/resouces]
## Create [POST]
...
### List all Resources [GET]
...
# One Resource [/resource/{id}]
## Retrieve the Resource [GET]
...
希望這可以幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.