Men*_*hak 22 apiary.io apiblueprint
我们正在考虑使用API蓝图.在某些情况下,我们希望一个请求返回正确的响应,另一个请求返回"错误"响应,例如,400 bad request以便其他开发人员可以在apiary.io上使用两种类型的响应来处理模拟API并处理它他们的应用.
我在下面创建了一个完全随意的例子,
## 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][]
Run Code Online (Sandbox Code Playgroud)
现在我想以某种方式添加回复 /thing/40
+ Response 400
{ "error" : "Invalid request" }
Run Code Online (Sandbox Code Playgroud)
但我不确定如何使用API Blueprint执行此操作.这可以在apiary.io的"旧"风格下实现,但我们想继续使用新的语法
Zde*_*nek 12
要记录多个响应,只需将其添加到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" }
Run Code Online (Sandbox Code Playgroud)
注意,目前没有专门的语法来讨论条件(返回此响应时).你可以讨论它,无论如何你喜欢它,例如:
+ Response 400 (application/json)
This response is returned when no `Thing` for given `id` exists.
+ Body
Run Code Online (Sandbox Code Playgroud)
如果您正在使用Apiary mock,请记住默认情况下会返回列出的第一个响应,除非您另外使用prefer HTTP标头.