简体   繁体   English

REST API设计,用于在资源上运行转换

[英]REST API design for running a transformation on a resource

So I know this is crazy from a security standpoint, but let's say I have a posts resource at /posts/ and I'd like an admin to be able to trigger a transformation on the collection (in this case, a simple data migration). 因此,从安全角度来看,我知道这很疯狂,但是假设我在/posts/拥有一个posts资源,并且我希望管理员能够触发集合的转换(在这种情况下,是简单的数据迁移) 。

How should I design the URL for something like that? 我应该如何设计类似这样的URL? It's basically a remote procedure: "take all the posts, modify them, and save them", which is why it is hard to shoehorn onto REST. 从根本上讲,这是一个远程过程:“获取所有帖子,对其进行修改,然后保存它们”,这就是为什么很难在REST上穿梭。

I ended up just doing POST /posts/name-of-transform . 我最终只是执行POST /posts/name-of-transform It's going to be hacky either way :( 无论哪种方式,它都会很笨拙:(

So what you want is to update a collection right? 因此,您想要的是更新收藏集吗?

I think what you're looking for is the http PATCH method. 我认为您正在寻找的是http PATCH方法。 It will acte pretty much like your POST method but instead of creating the ressources it will update them. 它的行为与您的POST方法非常相似,但它不会创建资源,而是会更新资源。

You can find more about the PATCH method at this address : https://restful-api-design.readthedocs.org/en/latest/methods.html 您可以在以下地址找到有关PATCH方法的更多信息: https : //restful-api-design.readthedocs.org/en/latest/methods.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM