0

我正在使用 Dredd 来测试我编写的 API。在我尝试改变资源中的操作 uri 之前,它工作正常。当我有表格的动作时

## Retrieve Task [GET /task/{id}]

它向 Drakov 发送]附加请求。此 Drakov 服务器正在运行蓝图文档。

Drakov 0.1.16      Listening on port 8090
[LOG] GET /task/myid]
[LOG] DELETE /task/myid]
[LOG] GET /task/myid]

你可以看到这个请求最后有一个额外]的。

这是我的蓝图。它是Api Blueprint 示例中示例的子集:

FORMAT: 1A

# Advanced Action API
A resource action is – in fact – a state transition. This API example demonstrates an action - state transition - to another resource.

## API Blueprint

# Tasks [/tasks/tasks{?status,priority}]

+ Parameters
    + status  `test` (string)
    + priority `1` (number)

## Retrieve Task [GET /task/{id}]
This is a state transition to another resource

+ Parameters
    + id: `myid` (string)

+ Response 200 (application/json)

        {
            "id": 123,
            "name": "Go to gym",
            "done": false,
            "type": "task"
        }

我究竟做错了什么?

4

1 回答 1

5

Your API Blueprint has multiple errors. For instance,

+ Parameters
  + status  `test` (string)
  + priority `1` (number)

...should be:

+ Parameters
  + status: `test` (string)
  + priority: `1` (number)

Also, you are defining a resource Tasks with URI Template /tasks/tasks{?status,priority} and then you are trying to define a GET action for the resource with a different URI Template. That is confusing.

I tried to create a sample API Blueprint (saved as sample-blueprint.md) like this:

FORMAT: 1A

# My API

## Task [/task/{id}]

### Retrieve Task [GET]

+ Parameters
    + id: `123` (string)

+ Response 200 (application/json)

        {
            "id": 123,
            "name": "Go to gym",
            "done": false,
            "type": "task"
        }

Then I launched a Drakov server in one terminal like this:

drakov -f *.md

Then I tried to run Dredd:

dredd sample-blueprint.md http://localhost:3000

Everything passed correctly:

$ dredd sample-blueprint.md http://localhost:3000
info: Beginning Dredd testing...
pass: GET /task/123 duration: 42ms
complete: 1 passing, 0 failing, 0 errors, 0 skipped, 1 total
complete: Tests took 50ms

Is this something you originally wanted to achieve?

于 2016-01-27T15:48:37.157 回答