GET /vehicles/{id}/command/honk_horn如这篇文章所示:
https://news.ycombinator.com/item?id=7961944
对于honk_horn资源应该使用哪个动词存在争论。答案包括:
也许问题的根源在于honk_horn实际上是一个操作,而不是一个资源,所以在这个特殊的情况下,应该如何定义为API来在保留RESTful的同时发出命令呢?
发布于 2014-07-27 08:55:58
也许问题的根源在于honk_horn实际上是一种行为而不是一种资源。
是的,我会这么说,这是问题的核心。面向资源和基于超媒体的方法可能如下所示(使用Mason https://github.com/JornWildt/Mason来描述操作):
GET /vehicles/12345/horn => return status of horn (a resource in itself)
{
volume: 5,
numberOfHonks: 1025,
@actions:
{
"honk":
{
type: "void",
href: "/vehicles/12345/horn/honks",
method: "POST",
title: "POST here to honk horn once"
}
}
}
GET /vehicles/12345/horn/honks => return previous honks (a resource in itself)
{
numberOfHonks: 1025,
honks:
[
{ date: "2010-12-24T10:24:12" },
{ date: "2010-12-24T10:24:14" },
{ date: "2010-12-24T10:24:20" },
... 1022 other honks (or perhaps only latest top 100 honks)
]
}
POST /vehicles/12345/horn/honks => Add one honk (empty payload - or maybe even include volume and pitch ...)有趣的运动:-)
https://stackoverflow.com/questions/24977150
复制相似问题