关于restful的几点疑惑,请问大家是怎么解决的?

1)每个rest请求中只能标注一种操作方法(如:GET、POST),但实际上每个请求中可能不止一种操作,这个大家怎么解决的?

举例:GET请求中,后台实际上还进行了日志记录,或其他修改操作,那rest规范岂不是被污染了

2)每个rest请求,只能对一种资源进行请求,那如果想要的是个复合资源,比如取出指定资源的所有关联的数据,那岂不是也会造成rest污染?

举例:
GET /zoos/1/animal/1;
但实际上想要把1号动物所属的动物园信息,动物园所属公司信息全部返回,那是不是造成了污染?

有好的restful api规范或restful规范框架类的东西也欢迎推荐下!!

阅读 1.5k
1 个回答

我的理解,这个请求的URL只是代表这个请求的目的是获取一号动物园的一号动物,也就是说最终返回的是一号动物。并不代表不能进行其他操作。然后你在接口里面记录了日志并不代表污染。

https://hackernoon.com/restful-api-designing-guidelines-the-b...

然后,你可以看下resource那里。

Resource is an object or representation of something, which has some
associated data with it and there can be set of methods to operate on
it. E.g. Animals, schools and employees are resources and delete, add,
update are the operations to be performed on these resources.

Collections are set of resources, e.g Companies is the collection of
Company resource.

URL (Uniform Resource Locator) is a path through which a resource can
be located and some actions can be performed on it.

重点在这句:URL就是一个路径,这个路径指示了resource的位置和这个resource能被什么actions操作。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进