表示“即发即忘"的 HTTP 方法RESTful 服务中的操作 [英] HTTP method to represent "fire and forget" actions in RESTful service

查看:24
本文介绍了表示“即发即忘"的 HTTP 方法RESTful 服务中的操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑到 REST,将 HTTP 方法映射到 CRUD 操作相对容易:POST 用于创建,GET 用于读取等.但是即发即弃"操作呢?哪种 HTTP 方法最能代表触发并忘记操作,例如触发批处理作业(其中没有响应发送回调用者)?

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 会浮现在脑海中,但我认为 GET 也是一种合适的方法,因为 99% 的时间您只为这些类型的操作提供一堆参数.你怎么认为?

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 会浮现在脑海中,但我认为 GET 是一种更合适的方法,因为 99% 的时间您只为这些类型的操作提供一堆参数.你怎么认为?

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?


在您的示例中,如果批处理作业不影响任何对象的外部可见状态,那么您可以将其实现为批处理作业.但是,您可以将批处理作业建模为具有关联资源容器的资源.

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.

您可以使用 Post 来创建新的 BatchJob 资源,并允许用户执行 GET 以查看到目前为止的作业进度.您可以对资源容器执行 GET 以列出所有正在运行的批处理作业,可能调用 DELETE 来终止一个.

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 方法RESTful 服务中的操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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