本文介绍了Apiary.io-具有不同参数的多个响应(200)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在尝试通过不同的参数获得不同的响应,但是某些方法不起作用.

I am trying to get different responses passing different parameters but something is not working.

这是我的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时,响应始终是相同的:

But when calling /questions/1 or /questions/2 the response is always the same:

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

怎么了?

谢谢

推荐答案

您的蓝图没有问题.恐怕Apiary Mock太简单了,它总是默认返回指定的第一个响应(内容协商允许).

Nothing is wrong with your blueprint. I am afraid the Apiary Mock is rather simplistic and always returns the first response specified (content-negotiation permitting) as default.

请参阅Apiary上的调用非默认响应" http://support.apiary.io/knowledgebase/articles/117119-handling-multiple-actions-on-a-single-resource ,以了解如何(按需)调用另一个响应.

See "Invoking non-default responses" at Apiary http://support.apiary.io/knowledgebase/articles/117119-handling-multiple-actions-on-a-single-resource to see how to invoke (on demand) another response.

还要注意,API Blueprint中有一种提议的语法,用于明确说明将哪些参数值绑定到特定响应– https://github.com/apiaryio/api-blueprint/issues/58

Also note there is a proposed syntax in API Blueprint to explicitly state what values of parameters are tied to a particular response – https://github.com/apiaryio/api-blueprint/issues/58

但是目前尚不清楚Apiary的模拟是否会利用这一点.

However whether will Apiary's mock take benefit of this is unclear at the moment.

这篇关于Apiary.io-具有不同参数的多个响应(200)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 06:05