【发布时间】:2013-11-12 01:04:31
【问题描述】:
我们有一个现有的 API,我们正在尝试为其构建蓝图,它要求某些请求主体是 URI 编码的 JSON。
有没有办法将正文指定为“像这样,但已编码”?
现有(纯文本)文档仅显示 JSON,以及在发送前对其进行编码的轻快提示:
POST /blah/blah/blah
Content-Type: application/x-www-form-urlencoded
Parameters: (x-www-form-urlencoded)
{ "title": "Buy cheese and bread for breakfast." }
但是使用 Blueprint——尤其是 apiary.io 上的 Blueprint——你真的必须展示真实的身体。这是完全不可读的:
### Create a Note [POST]
+ Request (application/x-www-form-urlencoded)
%7B%20%22title%22%3A%20%22Buy%20cheese%20and%20bread%20for%20breakfast.%22%20%7D
但在蓝图中指定可读文本失败(返回参数错误):
### Create a Note [POST]
+ Request (application/x-www-form-urlencoded)
{ "title": "Buy cheese and bread for breakfast." }
真正的症结在于当我让 Apiary 与我的真实服务器对话时:可读请求失败(因为它未编码),而不可读请求成功(因为根据需要,它是)。
【问题讨论】:
-
所以如果我是正确的,问题是是否可以为
application/x-www-form-urlencodedConten-Type 的消息体声明未编码的 JSON,以便 API 蓝图(解析器)在期间对其进行编码解析? -
是的,就是这样。