标签: apiary

如何在Go中的POST请求中发送JSON字符串

我尝试使用Apiary并制作了一个通用模板来将JSON发送到模拟服务器并拥有以下代码:

package main

import (
    "encoding/json"
    "fmt"
    "github.com/jmcvetta/napping"
    "log"
    "net/http"
)

func main() {
    url := "http://restapi3.apiary.io/notes"
    fmt.Println("URL:>", url)

    s := napping.Session{}
    h := &http.Header{}
    h.Set("X-Custom-Header", "myvalue")
    s.Header = h

    var jsonStr = []byte(`
{
    "title": "Buy cheese and bread for breakfast."
}`)

    var data map[string]json.RawMessage
    err := json.Unmarshal(jsonStr, &data)
    if err != nil {
        fmt.Println(err)
    }

    resp, err := s.Post(url, &data, nil, nil)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println("response Status:", resp.Status())
    fmt.Println("response Headers:", resp.HttpResponse().Header)
    fmt.Println("response Body:", resp.RawText()) …
Run Code Online (Sandbox Code Playgroud)

rest json go apiary

210
推荐指数
6
解决办法
31万
查看次数

尝试使用API​​蓝图中的数据结构描述请求和响应

我正在尝试使用API​​ Blueprint记录端点,使用规范的新Attributes和DataStructures部分.

我的请求有效负载如下所示:

{
    "url": "http://requestb.in/11v7i7e1",
    "active": true,
    "types": [
        {
            "name": "sales",
            "version": "2.0"
        },
        {
            "name": "products",
            "version": "2.0"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

我的响应有效负载看起来像这样:

{
  "data": {
    "id": "dc85058a-a683-11e4-ef46-e9431a15be8c",
    "url": "http://requestb.in/11v7i7e1",
    "active": true,
    "types": [
      {
        "name": "products",
        "version": "2.0"
      },
      {
        "name": "sales",
        "version": "2.0"
      }
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)

我尝试了以下API Blueprint markdown:

FORMAT: 1A

# Vend REST API 2.0

# Group Webhooks

## api/2.0/webhooks [/webhooks]

### List all Webhooks [GET]
Returns a list of Webhooks created by the …
Run Code Online (Sandbox Code Playgroud)

api apiary.io apiblueprint apiary mson

11
推荐指数
1
解决办法
4428
查看次数

Apiary.io - 具有不同参数的多个响应(200)

我试图通过不同的参数获得不同的响应,但有些东西不起作用.

这是我的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"
        }
Run Code Online (Sandbox Code Playgroud)

但是在调用/ questions/1或/ questions/2时,响应始终是相同的:

{
    "id": "1",
    "name": "Marco"
}
Run Code Online (Sandbox Code Playgroud)

怎么了?

谢谢

rest restful-architecture apiary.io apiblueprint apiary

11
推荐指数
1
解决办法
4934
查看次数

Apiary:是否可以记录JSON响应字段是什么?

我想记录实际的JSON字段本身代表什么.

我已经记录了GET语句和参数,但这并没有为用户提供完整的文档.

因此,在下面的示例中,我将如何添加有关"OtherFields"的注释.这支持吗?或者我是否需要在其他地方制作配套文件.

## View Applications [/cat{?sort}{&order}{&page}]
### List all Applications 
### Get List of Applications [GET]
+ Parameters
    + sort (optional, string) ... `sort` parameter is used to specify which criteria to use for sorting. One of the following strings may be used: 
    `"NAME", 
    "RATING", "QUALITY" ,
    "RISKLEVEL", `

    + order (optional, string) ... `order` parameter is used to specify which order to use if sorting is used. One of the following strings may be used: 
    `"ASC", 
    "DESC"`

    + …
Run Code Online (Sandbox Code Playgroud)

json apiblueprint apiary

9
推荐指数
2
解决办法
5985
查看次数

如何在apiary.io中更改API Doc的所有权?

我想要的是更改与API Doc关联的主电子邮件,因此当我与其他人共享该文档时,他们会看到新的电子邮件,而不是我的.那封新电子邮件有一个apiary.io,这就是为什么我在谈论所有权转移.

apiary.io apiary

9
推荐指数
1
解决办法
1057
查看次数

蜂房多个蓝图文件合二为一

嗨我正在使用Apiary维护我的REST API文档,因为我们的代码库正在增长,我们的API文档越来越大.将所有API放在单个蓝图文件中变得非常困难,我们是否可以将它们正确地组织成多个文件并在蜂房内显示它们.

apiary.io apiary

9
推荐指数
1
解决办法
1933
查看次数

如何在Apiary.io中显示嵌套属性定义

我的数据结构定义如下:

# Data Structures

## PlayerRank (object)
Represents the minimum amount of data the the client needs to send to give rank information about a particular Player in a particular Played Game.
+ playerId (number, required) - NemeStats unique identifier for the Player.
+ gameRank (number, required) - The corresponding rank of the Player in this Played Game. A rank of 1 means the Player got first place, 2 means second place, and so on.
+ pointsScored (number, optional) - …
Run Code Online (Sandbox Code Playgroud)

apiary.io apiblueprint apiary

9
推荐指数
1
解决办法
2292
查看次数

表示输入参数是Apiary中的日期/时间的正确格式是什么?

我正在编辑我正在处理的项目的一些Apiary文档,并且需要表示我的一个API调用的参数是一个日期时间字符串.蜂房似乎在扼杀这个参数的格式,所以我想知道在Apiary中记录这个参数的建议方法是什么.

为了演示,我从Apiary获取了标准的默认文档并修改了Choice文档以获取类似的datetime对象:

## Choice [/questions/{question_id}/choices/{choice_id}/{datetime}]

+ Parameters
    + question_id: 1 (required, number) - ID of the Question in form of an integer
    + choice_id: 1 (required, number) - ID of the Choice in form of an integer
    + datetime: 2015-05-05T12:30:00 (optional, date) - The date/time (ISO8601 format) associated with this choice
Run Code Online (Sandbox Code Playgroud)

最终结果如下:

datetime
05-05T12:30:00 (optional, date) - The date/time (ISO8601 format) that all returned events should be greater than or equal to Example: 2015.
Run Code Online (Sandbox Code Playgroud)

这显然是错误的,甚至写下示例值.破折号(-)是一个特殊的角色,在这里引起悲伤.这样做的推荐方法是什么?

apiary.io apiblueprint apiary

9
推荐指数
1
解决办法
3524
查看次数

如何为Swagger中的内容类型:text/html的响应主体提供示例值(使用dredd进行测试)

我有一个API调用,响应200 OK并返回一个HTML.我想将此添加到我的API文档中(特别是因为我使用dredd验证它,除非我提供预期的响应体,测试失败).我怎么会在Swagger这样做?

---更多细节---我对API调用的响应是200 OK并且有一行响应正文:

<html><body>You are being <a href="https://my.domain.com/users/sign_in">redirected</a>.</body></html>

我可以使用以下格式轻松定义蓝图中的响应主体:

 + Response 302 (text/html; charset=utf-8)

     + Body

         `<html><body>You are being <a href="https://my.domain.com/users/sign_in">redirected</a>.</body></html>`
Run Code Online (Sandbox Code Playgroud)

但我不知道如何在Swagger中做到这一点.我能找到的几乎所有例子都是针对应用程序/ json响应(可以理解),我无法猜测这种响应的正确语法.

我的文档中相关的招摇文本是这样的(到目前为止没有指定响应主体,因此空主体dredd失败,因为响应主体应该是<html><body>You are being <a href="https://my.domain.com/users/sign_in">redirected</a>.</body></html>):

# this is my API spec in YAML
swagger: '2.0'
info:
  title: My API (Swagger)
  description: blablabla
  version: "1.0.0"
# the domain of the service
host: my.domain.com
# array of all schemes that your API supports
schemes:
  - https
# will be prefixed to all paths
basePath: /
produces: …
Run Code Online (Sandbox Code Playgroud)

swagger apiary.io swagger-ui apiary swagger-2.0

7
推荐指数
2
解决办法
5890
查看次数

在 API 蓝图中表示文件上传

我们有一个 API 端点,可以在其中上传图像文件以及文件名(字符串)和描述(字符串)。

养蜂场/API 蓝图不允许我拥有类似的东西:

+ Request (multipart/form-data)

  + Headers

              Authorization: [key]

  + Attributes
      + name (string, required) - A human-readable name of the Catalog Item
      + description (string, optional) - A human readable description of the Catalog Item
      + image (file, optional) - An image file corresponding to the Catalog Item
Run Code Online (Sandbox Code Playgroud)

我得到:

base type 'file' is not defined in the document

有没有办法在 API 蓝图中表示多部分/表单数据(例如上面的内容)?

apiary.io apiblueprint apiary

6
推荐指数
0
解决办法
632
查看次数