HTTP方法重新present"消防,忘记"在RESTful服务行动 [英] HTTP method to represent "fire and forget" actions in RESTful service

查看:178
本文介绍了HTTP方法重新present"消防,忘记"在RESTful服务行动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于REST的思考,这是比较容易映射HTTP方法CRUD操作:POST的创建,获取用于读取等,但什么是射后不理的行为?什么HTTP方法会重新最好present火灾,忘记动作,如触发一个批处理作业(其中没有响应发送回调用者)?

POST会映入脑海,但我觉得GET也是一个合适的方法,因为99%的时间,你只提供了一堆参数,这些类型的操作。你怎么看?


解决方案

  

POST会映入脑海,但我认为得到的是一个更合适的方法,因为99%的时间,你只提供了一堆参数,这些类型的操作。你怎么看?


外部状态

我认为您使用参数的数量无关。你们用动词。关键的问题是你改变外部可见的状态呢?

结果

BatchJob资源

在你的榜样,如果批处理作业不影响任何对象的外部可见的状态,那么你可以实现它作为批处理作业。然而,你可以在你的批处理作业建模为具有相关的资源容器的资源。

您可以使用一个帖子来创建一个新的BatchJob资源,并允许用户做一个能看到作业进度为止。你可以做资源容器上的GET列出所有正在运行的批处理作业,可能是调用delete杀一。

Thinking about REST, it's relatively easy to map HTTP methods to CRUD actions: POST for create, GET for read, etc. But what about "fire and forget" actions? What HTTP method would best represent a fire and forget action such as triggering a batch job (in which no response is sent back to the caller)?

POST would spring to mind, but I think GET is also an appropriate method because 99% of the time you only supply a bunch of parameters to these types of actions. What do you think?

解决方案

POST would spring to mind, but I think GET is a more appropriate method because 99% of the time you only supply a bunch of parameters to these types of actions. What do you think?

External State

I think that the number of parameters you use has nothing to do with the verb you use. The key issue is are you changing externally visible state?


BatchJob Resources

In your example, if the batch job does not affect the externally visible state of any object then you could implement it as a batch job. However you could model your batch job as a resource with an associated resource container.

You could use a Post to create a new BatchJob resource and allow the user to do a GET to see the progress of the job so far. You could do a GET on the resource container to list all of the running batch jobs, possibly calling DELETE to kill one.

这篇关于HTTP方法重新present"消防,忘记"在RESTful服务行动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆