Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rest 类型定义方法_Rest_Api_Raml - Fatal编程技术网

Rest 类型定义方法

Rest 类型定义方法,rest,api,raml,Rest,Api,Raml,假设我有一个端点支持三种方法:GET、POST和PUT 将返回的类型包含两个属性:id和名称。两者都是必需的 我的问题是如何在RAML定义中定义这种类型,因为在POST上,id应该自动装箱,而在PUT上,id将是一个URI参数。你们是否创建了两种类型,一种用于GET,另一种用于PUT、POST,或者对所有操作使用相同的类型,声明id为非必需的 很抱歉,如果这是一个如此基本的问题,但我搜索了这个,没有得到任何结论性的回答 非常感谢 也许您可以提供一个示例,说明您希望它如何工作。另外,请指定您目前使

假设我有一个端点支持三种方法:GET、POST和PUT

将返回的类型包含两个属性:id和名称。两者都是必需的

我的问题是如何在RAML定义中定义这种类型,因为在POST上,id应该自动装箱,而在PUT上,id将是一个URI参数。你们是否创建了两种类型,一种用于GET,另一种用于PUT、POST,或者对所有操作使用相同的类型,声明id为非必需的

很抱歉,如果这是一个如此基本的问题,但我搜索了这个,没有得到任何结论性的回答


非常感谢

也许您可以提供一个示例,说明您希望它如何工作。另外,请指定您目前使用的RAML版本(假设为1.0)

您的端点提供了一个POST。这意味着您可以向其中添加项的某种集合。然后您可以使用GET来检索这样的项目

您可以为集合中的某个项目创建第二个端点:您将得到一个/collection all items和一个/collection/12345678单独的项目,特别是id为12345678的项目 或者,您可以使用查询字符串筛选集合以查找特定项:/collection?id=12345678恰好包含一项而不是多项的集合子集 也许,你也可以研究一下这个词的用法

举例说明:

/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
请注意,我的例子并不完全正确。这是关于概念,而不是精确的语法