0

我在 Apiary 蓝图示例中看到了以下操作部分。当用户传递错误的参数时,我想以 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.

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

4

1 回答 1

0

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

于 2015-04-24T06:59:43.403 回答