问题描述
众所周知,ReST Web服务无法保持状态-在考虑大型数据库事务时,这对我来说是个问题,我想知道您是否可以提供帮助.
As we all know a ReST web service cannot hold state - this is a problem for me now when I am considering large database transactions and I wonder if you can help.
我的ReST Web服务具有一个主要角色-对数据库执行CRUD操作.问题是是否必须查询具有数千行的表并将其作为XML发送回客户端-这不好.保持请求成千上万条记录的效率非常低,但是您无法使用REST Web服务进行部分事务(即在Oracle中使用ROWNUM关键字).那么您如何解决这个问题?
My ReST web service has one major role - to do CRUD operations against a database. Problem is if I have to query a table with thousands of rows and send that back to the client as XML - this is not good. It's highly inefficient to keep requesting for thousands of records BUT you cannot do partial transactions (i.e. using ROWNUM keyword in Oracle) with a REST web service. So how do you get round this?
一次从表100中获取记录的一种可能方法是:
One possible way to get records from a table 100 at a time would be:
http://mywebservice/employees/0/100
我保留上一次提交的请求(即100)的状态
I hold state for the last request submitted i.e 100
下一个请求将是:
http://mywebservice/employees/101/200
,依此类推.但是,这是否完全让人放松?
and so on. But is this strictly restful?
推荐答案
您提到了CRUD,但是您的示例仅看起来像是读操作.为什么不介绍分页?
You mentioned CRUD but your example looks like read-action only. Why don't you introduce paging?
# items 0 to 99
GET /employees?page=0&size=100
# items 100 to 199
GET /employees?page=1&size=100
目前尚不清楚您在示例中所指的是哪种状态.谈到HTTP上的Restful API,是的,HTTP本身就是一个无状态协议,但是整个系统肯定具有状态,状态会随着时间而变化(例如,执行写操作或POST时).
It is not clear which state you mean in your example. Talking about Restful over HTTP api, yes HTTP is itself a stateless protocol, but the overall system surely has a state, which can change over time (e.g. when doing write action á la POST).
也许您可以举一个示例,尝试通过Restful api公开哪些写操作(您提到了交易)?
Maybe you can give example which write actions (you mentioned transactions) you are trying to expose through Restful api?
这篇关于REST和大型数据库查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!