作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们正在考虑使用 API 蓝图。在某些情况下,我们希望一个请求返回正确的响应,而另一个请求返回“错误”响应,例如 400 错误请求
,以便其他开发人员可以针对养蜂场上的模拟 API 进行操作。 io 具有两种类型的响应并在其应用程序中处理它。
我在下面创建了一个完全任意的示例,
## Thing [/thing/{id}]
Gets a thing but the thing id must be a prime number!
+ Parameters
+ id (string) ... ID of the thing, a prime number!
+ Model (application/json)
The thing itself.
+ Body
{
"description": "It is green"
}
### Retrieve a Single Gist [GET]
+ Response 200
[Gist][]
现在我想添加对 /thing/40
的响应
+ Response 400
{ "error" : "Invalid request" }
但我不确定如何使用 API 蓝图来做到这一点。这在 apiary.io 上的“旧”样式下是可以实现的,但我们希望继续使用新语法
最佳答案
要记录多个响应,只需将其添加到 Response 200
之后,如下所示:
## Thing [/thing/{id}]
Gets a thing but the thing id must be a prime number!
+ Parameters
+ id (string) ... ID of the thing, a prime number!
+ Model (application/json)
The thing itself.
+ Body
{
"description": "It is green"
}
### Retrieve a Single Gist [GET]
+ Response 200
[Thing][]
+ Response 400 (application/json)
{ "error" : "Invalid request" }
请注意,当前没有专用语法来讨论条件(当返回此响应时)。您可以随心所欲地讨论它,例如:
+ Response 400 (application/json)
This response is returned when no `Thing` for given `id` exists.
+ Body
如果您使用 Apiary 模拟,请记住默认情况下会返回列出的第一个响应,除非您另有说明使用 prefer HTTP header .
关于apiary.io - 如何从具有不同参数的单个端点获得多个响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21279191/
我是一名优秀的程序员,十分优秀!