2017-01-06 63 views
0

假設我有一個支持三種方法的端點:GET,POST和PUT。類型定義方法

將返回的類型包含兩個屬性:idname。兩者都是required

我的問題是關於如何定義這種類型的RAML定義,因爲在POST,在id應自動裝箱和PUTid將是一個URI參數。你們是否創建了兩個Types(其中一個用於GET,其他用於PUT,POST),或者對所有操作使用相同類型,聲明id不是required

對不起,如果這似乎是一個這樣的基本問題,但我搜索了這一點,並沒有得到任何確鑿的答覆。

非常感謝!

回答

1

也許你可以提供一個你期望它如何工作的例子。還請指定您正在使用的RAML版本(現在假設爲1.0)。

您的端點提供POST。這意味着您可以添加項目的某種集合。然後你可以使用GET來檢索這樣的項目。

  • 你可以爲你收集的項目創建第二個端點:你會最終有一個/collection(所有項目)和/collection/12345678(單獨一個項目,具體而言,ID爲12345678項)
  • 或者您可以使用查詢字符串來篩選您的收藏找到該特定項目:/collection?id=12345678

也許(這恰好包含一個項目而不是多個集合的子集),你也可以考慮使用uriParameters

舉例說明:

/types: 
    myidtype: 
     type: string 
     pattern: ^[0-9]{8}$ 
/collection: 
    get: # to retrieve the entire collection 
     queryParameters: # to be able to filter the collection into a subset of 1 or more items 
      id: 
       type: myidtype 
       required: false 
      name: 
       type: string 
       required: false 
    post: # to create a new item and add it to the collection, id and name will go in the body 
    /{myId}: # this is one item 
     uriParameters: 
      myId: 
       type: myidtype 
     get: # to retrieve all information on this item 
     post: # to post some property to this item 

請注意,我的例子並不完全正確的。這是關於概念而不是確切的語法。

相關問題