api蓝图中给定端点的多个响应

时间:2014-11-16 09:55:56

标签: apiblueprint apiary.io

API蓝图是否可以为给定端点定义一组可能的响应?

例如,如果我有一个端点,例如/ movie / {id},我希望能够定义一组电影记录,以便在模拟服务器中我可以GET / movie / 1或GET / movie / 2或GET / movie / 3并获得相关记录。

我见过的例子似乎都只定义了一种可能的回应。

2 个答案:

答案 0 :(得分:0)

使用单个操作无法模拟此操作,但有一种解决方法。

FORMAT: 1A

# Multi

## GET /movie/1

+ Response 200 (application/json)

        { "id": 1, "title": "First" }

## GET /movie/2

+ Response 200 (application/json)

        { "id": 2, "title": "Second" }

## GET /movie/3

+ Response 200 (application/json)

        { "id": 3, "title": "Third" }

## GET /movie/{id}

+ Parameters
    + id (required, number, `42`) ... Blah.

+ Response 200 (application/json)

        { "id": 42, "title": "First" }

现在,如果您点击/movie/2,模拟服务器会发送相应的响应。感谢。

答案 1 :(得分:0)

这是您使用Mulesoft(API设计器)在RAML文件中提供多个响应的方式,但是,如果您使用模拟服务进行测试,则将始终获得为测试设置的示例响应

/{id}:
    get:
      headers:
       Requester-Id:
        required: true
      responses:
        200:
          body:
            application/json:
              type: Account
              example:
                !include exapmle/AccountExample.raml

        400:
          body:
            application/json:
              example:
                {"message":"Error retrieving account for the provided id"}   
相关问题