开发者

REST and large database queries

开发者 https://www.devze.com 2023-01-29 11:52 出处:网络
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.

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.

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?

One possible way to get records from a table 100 at a time would be:

http://mywebservice/employees/0/100

I hold state for the last request submitted i.e 100

the next request would be:

http://mywebservice/employees/101/200

and so on. But is this strictly restf开发者_如何学Cul?


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

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).

Maybe you can give example which write actions (you mentioned transactions) you are trying to expose through Restful api?

0

精彩评论

暂无评论...
验证码 换一张
取 消