在Request负载中为我的参数提供动态值(POST x-www-form-urlencoded)

时间:2016-08-04 21:57:16

标签: apiblueprint

对于我的请求参数(在我的情况下,POST应用程序/ x-www-form-urlencoded具有两个参数用户名和密码),是否有一种方法(甚至有意义)甚至可以更改为基础的动态值某个函数或来自先前请求的服务器的返回值?

我有一个注册新用户请求的动机,我不时运行apiary.io,除非我手动更改用户名的示例值,我得到一个“使用已存在”的响应,而不是201我想要(因为这个请求已经在示例中使用用户名运行)。

我想要的是API文档中的一个值,它会在API调用的每次执行时发生变化(在那里使用一些随机数,或者能够让它从前一个返回一个值)请求)。

对于注册新用户API调用,您有什么建议可以解决我的“用户已存在”响应吗?

以下是我当前的API文档(相关部分):

## Registration [/users.json]
The `/users.json` resource handles registration of new user

### Register a New Patient [POST]
Register a new patient action sends email and password and registers
the new user in case it doesn't already exist

+ Request (application/x-www-form-urlencoded)
    + Attributes (Test User)

    + Body

        user[email]=username@example.com&user[password]=123456

+ Response 201 (application/json)

        {
            "id":500
        }

# Data Structures
## Test User (object) 
+ "user[email]" (string): "username@example.com" - user email
+ "user[password]" (string): "123456" - user password

提前致谢

1 个答案:

答案 0 :(得分:1)

您可以通过在通话中传递标题在Apiary模拟服务器中对此进行部分模拟,例如:

Prefer: status=200

请参阅https://help.apiary.io/tools/mock-server/#multiple-responses

一般情况下,模拟服务器还不够灵活且可编程,无法完全按照您的描述进行操作,例如条件,动态变量或随机响应。

我们正在努力加强这一点。如果您愿意,可以在此处评论您的要求: https://github.com/apiaryio/api-blueprint/issues/58

随时在Apiary(应用内聊天)或support@apiary.io上ping我们。

由于