如何回应Apiary中错误传递的参数?

时间:2015-04-23 10:16:47

标签: apiblueprint apiary.io apiary

我在Apiary蓝图示例中看到了以下Action部分。我想在用户传递错误参数时响应HTTP状态404。例如,当用户传递/ questions / xyz而不是/ questions / 1时。 正如你所看到的那样,我们定义了/ questions之后的参数必须是一个数字,但当我通过xyz而不是数字时,它会回答同一个对象。

## Questions [/questions/{question_id}]
An Questions object has the following attributes:

+ question - We can put some description for each attribute here.
+ published_at - An ISO8601 date when the question was published.
+ url (string) 
+ choices - An array of Choice objects.

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

### View an Questions Detail [GET]

+ Response 200 (application/json)

            {
                "question": "Favourite programming language?",
                "published_at": "2014-11-11T08:40:51.620Z",
                "url": "/questions/1",
                "choices": [
                    {   <!-- First Object -->
                        "choice": "Swift",
                        "url": "/questions/1/choices/1",
                        "votes": 2048
                    }
                ]
            }

+ Response 404 (text/plain)

    There is no such a message for the passed id. For example if you pass 'xyz' we expect to show this message.

请给我写完整的代码。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

我很抱歉,但不幸的是,Apiary还不支持基于请求中传递的正文和参数的条件响应。