Apiary.io - 具有不同参数的多个响应(200)

时间:2015-06-18 09:37:38

标签: rest restful-architecture apiblueprint apiary.io apiary

我正在尝试通过不同的参数获得不同的响应,但有些东西无效。

这是我的API:

## Question [/questions/{question_id}]

A Question object has the following attributes:

+ Parameters
    + question_id: `1` (number, required) - ID of the Question in form of an integer

### View a Questions Detail [GET]

+ Request

+ Header

    X-Custom-Header : 1

+ Response 200 (application/json)

        {
            "id": "1",
            "name": "Marco"
        }


+ Request

+ Header

    X-Custom-Header : 2

+ Response 200 (application/json)

        {
            "id: "2",
            "name": "Lucas"
        }

但是在调用/ questions / 1或/ questions / 2时,响应始终是相同的:

{
    "id": "1",
    "name": "Marco"
}

有什么问题?

谢谢

2 个答案:

答案 0 :(得分:3)

你的蓝图没有错。我担心Apiary Mock相当简单,并且总是返回指定的第一个响应(内容协商允许)作为默认值。

参见"调用非默认响应"在Apiary http://support.apiary.io/knowledgebase/articles/117119-handling-multiple-actions-on-a-single-resource看看如何调用(按需)另一个响应。

另请注意,API Blueprint中提出了一种语法,用于明确说明哪些参数值与特定响应相关联 - https://github.com/apiaryio/api-blueprint/issues/58

然而,Apiary嘲笑是否会受益于此目前尚不清楚。

答案 1 :(得分:2)

我相信有一个简单的解决方案可以在不使用标题的情况下执行此操作:

创建不同的资源(每个记录一个),因此每个资源都会生成一个URL。

## Note20 [/notes/20]

### Get notes20 [GET]

+ Response 200 (application/json)

        {
            "id" : 20,
            "name" : "note xxxx"
        } 

## Note21 [/notes/21]

### Get notes21 [GET]

+ Response 200 (application/json)

        {
            "id" : 21,
            "name" : "note yyyyy"
        } 
相关问题