gpt4 book ai didi

apiary.io - 如何从具有不同参数的单个端点获得多个响应?

转载 作者:行者123 更新时间:2023-12-02 23:40:41 24 4
gpt4 key购买 nike

我们正在考虑使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com