aspose file tools*
The moose likes Web Services and the fly likes RESTful web services and SQL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "RESTful web services and SQL" Watch "RESTful web services and SQL" New topic
Author

RESTful web services and SQL

Vladimir Shcherbina
Greenhorn

Joined: Nov 15, 2005
Posts: 20
Hi,

If RESTful web services are data-oriented, then is it make sense to invent some kind of webSQL on top of REST protocol in order to better aggregate REST requests in a client ?
Vladimir
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
You could, if you really want to, just pass the SQL query in as a GET parameter. You could also invent some mapping from SQL to a more traditional URL layout, but I would not recommend that either.

There are several rasons for this. One reason is that it's nice to be able to change the SQL and/or the underlying database structure without breaking lots of client implementations. Another reason is that exposing an SQL interface (translated or not) could inadvertently leave your application open to SQL injection attacks.

Usually, though, a service would be at a more coarse-grained level than a typical SQL query. The external interface should be in terms of consistent and complete domain items, not individual rows, columns or tables.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Vladimir Shcherbina
Greenhorn

Joined: Nov 15, 2005
Posts: 20
Hi,

When I wrote webSQL, I didn't mean to expose an underlaying database.
If there is some data structure (linked list), which is repesented by linked web pages (resources), then it will be great to be able to grab, say, two pages in the middle by some GETSql (instead of making a number of sequiential GETs). Does it make sense?
Leonard Richardson
author
Ranch Hand

Joined: Jun 08, 2007
Posts: 37
Vladimir, you can use HTTP pipelining (a feature of HTTP 1.1) to send batch GET and HEAD requests. You can also use Keep-Alive (another feature of HTTP 1.1) to make multiple HTTP requests without closing the TCP socket. Those optimizations should significantly cut down on your overhead. This is not covered in RWS, but HTTP: The Definitive Guide talks about it in chapter 4.
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Originally posted by Vladimir Shcherbina:
When I wrote webSQL, I didn't mean to expose an underlaying database.
If there is some data structure (linked list), which is repesented by linked web pages (resources), then it will be great to be able to grab, say, two pages in the middle by some GETSql (instead of making a number of sequiential GETs). Does it make sense?


OK. I think I understand now. It's an interesting idea.

My gut feeling is that this is likely to be too application-specific for something as general as an SQL-equivanet query language.

I have found that several of the REST APIs I have designed have allowed room for multiple ids in the URL. For example:



might retrieve data about the products with the three ids in a single request, or:



might fetch the six products on the twelfth page.

These are still RESTful requests, just ones which return aggregated data.

Is that along the lines of what you were asking, or have I missed the point again?
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Also, I have just remembered that I have successfully used XPath expressions in REST GET URLs to remotely query a large DOM object without needing to transfer the whole thing.

XPath might be a better fit than SQL if you are intending to query mostly tree-structured data.
Vladimir Shcherbina
Greenhorn

Joined: Nov 15, 2005
Posts: 20
Hi,

Yes, this looks like a solution (especially XPATH). I need to read the book in order to understand what is the RESTful added value to HTTP.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: RESTful web services and SQL