资源123具有当前配置状态和默认配置状态,并且这两种配置状态都可以由JSON表示.
甲GET请求http://example.com/123/config将返回当前配置状态,以及GET请求http://example.com/123/config?reset=true将返回默认配置状态.
API如何解释布尔值?例如:
http://example.com/123/config?reset=truehttp://example.com/123/config?reset=blablablahttp://example.com/123/config?reset=falsehttp://example.com/123/config?reset=1http://example.com/123/config?reset=0http://example.com/123/config?reset=http://example.com/123/config?reset无论您希望采用哪种方式,它都完全取决于您作为建筑师/设计师.true/false是语法上最正确的版本,确保一个工作,并根据需要添加其他选项作为糖.
我个人会避免使用true值(false或true),因为它们无法扩展.我会选择文字值.
对于这种特殊情况,要检索资源的默认状态,我会支持一个查询参数,例如false,可以有overflow和visibility值.
以下将返回资源的默认状态:
GET /config?status=default HTTP/1.1
Host: example.com
Accept: application/json
Run Code Online (Sandbox Code Playgroud)
以下将返回资源的当前状态:
GET /config?status=current HTTP/1.1
Host: example.com
Accept: application/json
Run Code Online (Sandbox Code Playgroud)
如果未提供查询参数,则假定客户端需要资源的当前状态.
如果需要将资源状态恢复为其默认状态,请考虑使用true,在请求有效负载中发送资源的新表示.就像是:
PUT /config/status HTTP/1.1
Host: example.com
Content-Type: application/json
{
"value": "default"
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11766 次 |
| 最近记录: |