REST and large database queries

2019-05-14 06:07发布

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 restful?

标签: database rest
1条回答
Ridiculous、
2楼-- · 2019-05-14 06:18

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?

查看更多
登录 后发表回答