Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
公开时态数据-这是RESTful吗?_Rest - Fatal编程技术网

公开时态数据-这是RESTful吗?

公开时态数据-这是RESTful吗?,rest,Rest,背景/背景: GET /zips/90210 200 OK {"zipCode":90210,"pickupLocationCode":"R","fromDate":"2013-01-01","thruDate":null, "_links":{"self":{"href":"/zips/90210"}, "latest":{"href":"/zips/90210"}}} PUT /zips/90210 {"zipCode":90210,"pickupLocati

背景/背景:

GET /zips/90210
200 OK

{"zipCode":90210,"pickupLocationCode":"R","fromDate":"2013-01-01","thruDate":null,
 "_links":{"self":{"href":"/zips/90210"},
           "latest":{"href":"/zips/90210"}}}
PUT /zips/90210

{"zipCode":90210,"pickupLocationCode":"U","fromDate":"2015-01-01","thruDate":null}
204 No Content
GET /zips/90210
200 OK

{"zipCode":90210,"pickupLocationCode":"U","fromDate":"2015-01-01","thruDate":null,
 "_links":{"self":{"href":"/zips/90210"},
           "previous":{"href":"/zips/90210/0"},
           "latest":{"href":"/zips/90210"}}}
GET /zips/90210/0
200 OK

{"zipCode":90210,"pickupLocationCode":"R","fromDate":"2013-01-01","thruDate":"2014-12-31",
 "_links":{"self":{"href":"/zips/90210/0"},
           "next":{"href":"/zips/90210"},
           "latest":{"href":"/zips/90210"}}}
DELETE /zips/90210
204 No Content
我有一个非常简单的用例,我正试图以此为契机,在公司内部建立对超媒体富API开发的支持。在优秀的stackoverflow社区的帮助下,我试图确定的是,我提议的实现是否符合所有条件,称自己为“RESTful”

正如所承诺的,这个用例非常简单——我们有一个数据表,其中我们根据每个zipcode跟踪某种位置分类代码。该表唯一有趣的一点是,通过起始/截止日期,我们有了有效性的概念:

表1

我们每年秋天都会收到更新的数据,从次年1月1日起生效。例如,如果上述zipcode被更新为新的“CODE”值,我们将对下表进行更改:

表2

当然,人们可以在睡眠中将此交互作为CRUD服务公开,称之为“RESTful”,并在短时间内完成。用于更新旧记录的“截止”日期;POST以插入反映新数据的记录

很简单,但正如我提到的,我正试图利用这个机会做一个超媒体案例研究——这是我提议的设计(通过一些示例请求传达)。下面是我建议如何从表状态1转换为表状态2:

请求1:

GET /zips/90210
200 OK

{"zipCode":90210,"pickupLocationCode":"R","fromDate":"2013-01-01","thruDate":null,
 "_links":{"self":{"href":"/zips/90210"},
           "latest":{"href":"/zips/90210"}}}
PUT /zips/90210

{"zipCode":90210,"pickupLocationCode":"U","fromDate":"2015-01-01","thruDate":null}
204 No Content
GET /zips/90210
200 OK

{"zipCode":90210,"pickupLocationCode":"U","fromDate":"2015-01-01","thruDate":null,
 "_links":{"self":{"href":"/zips/90210"},
           "previous":{"href":"/zips/90210/0"},
           "latest":{"href":"/zips/90210"}}}
GET /zips/90210/0
200 OK

{"zipCode":90210,"pickupLocationCode":"R","fromDate":"2013-01-01","thruDate":"2014-12-31",
 "_links":{"self":{"href":"/zips/90210/0"},
           "next":{"href":"/zips/90210"},
           "latest":{"href":"/zips/90210"}}}
DELETE /zips/90210
204 No Content
响应1:

GET /zips/90210
200 OK

{"zipCode":90210,"pickupLocationCode":"R","fromDate":"2013-01-01","thruDate":null,
 "_links":{"self":{"href":"/zips/90210"},
           "latest":{"href":"/zips/90210"}}}
PUT /zips/90210

{"zipCode":90210,"pickupLocationCode":"U","fromDate":"2015-01-01","thruDate":null}
204 No Content
GET /zips/90210
200 OK

{"zipCode":90210,"pickupLocationCode":"U","fromDate":"2015-01-01","thruDate":null,
 "_links":{"self":{"href":"/zips/90210"},
           "previous":{"href":"/zips/90210/0"},
           "latest":{"href":"/zips/90210"}}}
GET /zips/90210/0
200 OK

{"zipCode":90210,"pickupLocationCode":"R","fromDate":"2013-01-01","thruDate":"2014-12-31",
 "_links":{"self":{"href":"/zips/90210/0"},
           "next":{"href":"/zips/90210"},
           "latest":{"href":"/zips/90210"}}}
DELETE /zips/90210
204 No Content
请求2:

GET /zips/90210
200 OK

{"zipCode":90210,"pickupLocationCode":"R","fromDate":"2013-01-01","thruDate":null,
 "_links":{"self":{"href":"/zips/90210"},
           "latest":{"href":"/zips/90210"}}}
PUT /zips/90210

{"zipCode":90210,"pickupLocationCode":"U","fromDate":"2015-01-01","thruDate":null}
204 No Content
GET /zips/90210
200 OK

{"zipCode":90210,"pickupLocationCode":"U","fromDate":"2015-01-01","thruDate":null,
 "_links":{"self":{"href":"/zips/90210"},
           "previous":{"href":"/zips/90210/0"},
           "latest":{"href":"/zips/90210"}}}
GET /zips/90210/0
200 OK

{"zipCode":90210,"pickupLocationCode":"R","fromDate":"2013-01-01","thruDate":"2014-12-31",
 "_links":{"self":{"href":"/zips/90210/0"},
           "next":{"href":"/zips/90210"},
           "latest":{"href":"/zips/90210"}}}
DELETE /zips/90210
204 No Content
响应2:

GET /zips/90210
200 OK

{"zipCode":90210,"pickupLocationCode":"R","fromDate":"2013-01-01","thruDate":null,
 "_links":{"self":{"href":"/zips/90210"},
           "latest":{"href":"/zips/90210"}}}
PUT /zips/90210

{"zipCode":90210,"pickupLocationCode":"U","fromDate":"2015-01-01","thruDate":null}
204 No Content
GET /zips/90210
200 OK

{"zipCode":90210,"pickupLocationCode":"U","fromDate":"2015-01-01","thruDate":null,
 "_links":{"self":{"href":"/zips/90210"},
           "previous":{"href":"/zips/90210/0"},
           "latest":{"href":"/zips/90210"}}}
GET /zips/90210/0
200 OK

{"zipCode":90210,"pickupLocationCode":"R","fromDate":"2013-01-01","thruDate":"2014-12-31",
 "_links":{"self":{"href":"/zips/90210/0"},
           "next":{"href":"/zips/90210"},
           "latest":{"href":"/zips/90210"}}}
DELETE /zips/90210
204 No Content
请求3:

GET /zips/90210
200 OK

{"zipCode":90210,"pickupLocationCode":"R","fromDate":"2013-01-01","thruDate":null,
 "_links":{"self":{"href":"/zips/90210"},
           "latest":{"href":"/zips/90210"}}}
PUT /zips/90210

{"zipCode":90210,"pickupLocationCode":"U","fromDate":"2015-01-01","thruDate":null}
204 No Content
GET /zips/90210
200 OK

{"zipCode":90210,"pickupLocationCode":"U","fromDate":"2015-01-01","thruDate":null,
 "_links":{"self":{"href":"/zips/90210"},
           "previous":{"href":"/zips/90210/0"},
           "latest":{"href":"/zips/90210"}}}
GET /zips/90210/0
200 OK

{"zipCode":90210,"pickupLocationCode":"R","fromDate":"2013-01-01","thruDate":"2014-12-31",
 "_links":{"self":{"href":"/zips/90210/0"},
           "next":{"href":"/zips/90210"},
           "latest":{"href":"/zips/90210"}}}
DELETE /zips/90210
204 No Content
响应3:

GET /zips/90210
200 OK

{"zipCode":90210,"pickupLocationCode":"R","fromDate":"2013-01-01","thruDate":null,
 "_links":{"self":{"href":"/zips/90210"},
           "latest":{"href":"/zips/90210"}}}
PUT /zips/90210

{"zipCode":90210,"pickupLocationCode":"U","fromDate":"2015-01-01","thruDate":null}
204 No Content
GET /zips/90210
200 OK

{"zipCode":90210,"pickupLocationCode":"U","fromDate":"2015-01-01","thruDate":null,
 "_links":{"self":{"href":"/zips/90210"},
           "previous":{"href":"/zips/90210/0"},
           "latest":{"href":"/zips/90210"}}}
GET /zips/90210/0
200 OK

{"zipCode":90210,"pickupLocationCode":"R","fromDate":"2013-01-01","thruDate":"2014-12-31",
 "_links":{"self":{"href":"/zips/90210/0"},
           "next":{"href":"/zips/90210"},
           "latest":{"href":"/zips/90210"}}}
DELETE /zips/90210
204 No Content
请求4:

GET /zips/90210
200 OK

{"zipCode":90210,"pickupLocationCode":"R","fromDate":"2013-01-01","thruDate":null,
 "_links":{"self":{"href":"/zips/90210"},
           "latest":{"href":"/zips/90210"}}}
PUT /zips/90210

{"zipCode":90210,"pickupLocationCode":"U","fromDate":"2015-01-01","thruDate":null}
204 No Content
GET /zips/90210
200 OK

{"zipCode":90210,"pickupLocationCode":"U","fromDate":"2015-01-01","thruDate":null,
 "_links":{"self":{"href":"/zips/90210"},
           "previous":{"href":"/zips/90210/0"},
           "latest":{"href":"/zips/90210"}}}
GET /zips/90210/0
200 OK

{"zipCode":90210,"pickupLocationCode":"R","fromDate":"2013-01-01","thruDate":"2014-12-31",
 "_links":{"self":{"href":"/zips/90210/0"},
           "next":{"href":"/zips/90210"},
           "latest":{"href":"/zips/90210"}}}
DELETE /zips/90210
204 No Content
响应4:

GET /zips/90210
200 OK

{"zipCode":90210,"pickupLocationCode":"R","fromDate":"2013-01-01","thruDate":null,
 "_links":{"self":{"href":"/zips/90210"},
           "latest":{"href":"/zips/90210"}}}
PUT /zips/90210

{"zipCode":90210,"pickupLocationCode":"U","fromDate":"2015-01-01","thruDate":null}
204 No Content
GET /zips/90210
200 OK

{"zipCode":90210,"pickupLocationCode":"U","fromDate":"2015-01-01","thruDate":null,
 "_links":{"self":{"href":"/zips/90210"},
           "previous":{"href":"/zips/90210/0"},
           "latest":{"href":"/zips/90210"}}}
GET /zips/90210/0
200 OK

{"zipCode":90210,"pickupLocationCode":"R","fromDate":"2013-01-01","thruDate":"2014-12-31",
 "_links":{"self":{"href":"/zips/90210/0"},
           "next":{"href":"/zips/90210"},
           "latest":{"href":"/zips/90210"}}}
DELETE /zips/90210
204 No Content
请注意,输入请求2自动“过期”旧行(即设置截止日期),然后插入新行

我试图允许客户端(1)通过URL使用已知的业务密钥(例如“90210”)定位给定的zipcode,然后(2)通过超媒体(“下一个”、“上一个”、“最新的”链接rels),允许客户端在不同的时间点浏览zipcode的各种状态。我是走对了路还是在做傻事

使用这种设计,如果你曾经想“删除”一个zipcode(我猜这种情况很少——如果有过的话?——发生,但再次尝试将其作为一种学术练习,而不是任何东西),你可以做一些有趣的事情:

删除请求:

GET /zips/90210
200 OK

{"zipCode":90210,"pickupLocationCode":"R","fromDate":"2013-01-01","thruDate":null,
 "_links":{"self":{"href":"/zips/90210"},
           "latest":{"href":"/zips/90210"}}}
PUT /zips/90210

{"zipCode":90210,"pickupLocationCode":"U","fromDate":"2015-01-01","thruDate":null}
204 No Content
GET /zips/90210
200 OK

{"zipCode":90210,"pickupLocationCode":"U","fromDate":"2015-01-01","thruDate":null,
 "_links":{"self":{"href":"/zips/90210"},
           "previous":{"href":"/zips/90210/0"},
           "latest":{"href":"/zips/90210"}}}
GET /zips/90210/0
200 OK

{"zipCode":90210,"pickupLocationCode":"R","fromDate":"2013-01-01","thruDate":"2014-12-31",
 "_links":{"self":{"href":"/zips/90210/0"},
           "next":{"href":"/zips/90210"},
           "latest":{"href":"/zips/90210"}}}
DELETE /zips/90210
204 No Content
删除响应:

GET /zips/90210
200 OK

{"zipCode":90210,"pickupLocationCode":"R","fromDate":"2013-01-01","thruDate":null,
 "_links":{"self":{"href":"/zips/90210"},
           "latest":{"href":"/zips/90210"}}}
PUT /zips/90210

{"zipCode":90210,"pickupLocationCode":"U","fromDate":"2015-01-01","thruDate":null}
204 No Content
GET /zips/90210
200 OK

{"zipCode":90210,"pickupLocationCode":"U","fromDate":"2015-01-01","thruDate":null,
 "_links":{"self":{"href":"/zips/90210"},
           "previous":{"href":"/zips/90210/0"},
           "latest":{"href":"/zips/90210"}}}
GET /zips/90210/0
200 OK

{"zipCode":90210,"pickupLocationCode":"R","fromDate":"2013-01-01","thruDate":"2014-12-31",
 "_links":{"self":{"href":"/zips/90210/0"},
           "next":{"href":"/zips/90210"},
           "latest":{"href":"/zips/90210"}}}
DELETE /zips/90210
204 No Content
随后进入/zips/90210将为您提供:

303 See Other
Location: /zips/90210/0
这将允许您在(1)我们不再有任何“活动”数据的zipcode和(2)一开始就不存在的zipcode之间做出有价值的区分,例如:

GET /zips/99999
这会给你一个很好的404:

404 Not Found
插入一个新的zipcode(一个可能半频繁发生的用例)只需进行探索性的GET以确认zip当前不存在(即303 See Other或404 Not Found响应),然后向基本“/zips”URL发送帖子


任何反馈都将不胜感激

请求2的URI来自哪里?看起来像是带外信息?将
/0
改为原始URI并允许在引擎盖下进行版本跟踪有什么意义?哎呀,这是一个输入错误(我现在已经修复了,谢谢)。我的意图是,正如你所说,对原始URI确实有一个PUT。您在任何地方都没有提到自定义媒体类型。一个邮政编码和一组邮政编码的媒体类型是什么?这是一个很好的问题-我正在设想某种特定于应用程序的媒体类型(例如“application/vnd.myorg.zipcode+json”),但老实说,我还没有想到这一点。