REST 中的批处理 [英] Batching in REST

查看:31
本文介绍了REST 中的批处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于 Web 服务,将多个服务调用批处理为一条消息以减少远程调用的数量被认为是一种很好的做法.有没有办法用 RESTful 服务来做到这一点?

With web services it is considered a good practice to batch several service calls into one message to reduce a number of remote calls. Is there any way to do this with RESTful services?

推荐答案

我不明白在 REST 中批处理请求有什么意义.由于基于 REST 的服务中的 URL 代表要执行的操作和要执行的数据,因此批量请求会严重破坏概念模型.

I don't see how batching requests makes any sense in REST. Since the URL in a REST-based service represents the operation to perform and the data on which to perform it, making batch requests would seriously break the conceptual model.

如果您多次对相同数据执行相同操作,则例外.在这种情况下,您可以为请求参数传入多个值,也可以在正文中对此重复进行编码(但这仅适用于 PUT 或 POST).Gliffy REST API 支持通过

An exception would be if you were performing the same operation on the same data multiple times. In this case you can either pass in multiple values for a request parameter or encode this repetition in the body (however this would only really work for PUT or POST). The Gliffy REST API supports adding multiple users to the same folder via

POST /folders/ROOT/the/folder/name/users?userId=56&userId=87&userId=45

本质上是:

PUT /folders/ROOT/the/folder/name/users/56
PUT /folders/ROOT/the/folder/name/users/87
PUT /folders/ROOT/the/folder/name/users/45

正如另一位评论者指出的那样,可以通过请求参数完成 GET 的分页结果:

As the other commenter pointed out, paging results from a GET can be done via request parameters:

GET /some/list/of/resources?startIndex=10&pageSize=50

如果REST 服务支持它.

if the REST service supports it.

这篇关于REST 中的批处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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