Reputation: 14295
We're designing a data driven web app for mobile devices using jQuery Mobile for the interface. Does it make sense to use a RESTful interface to fetch the data? I can see how it's useful to have a website whose paths are RESTful because the user can easily manipulate the path and cross-navigate but does a REST bring any benefit if the AJAX calls are all hidden from the user (aside from making the API easy for other developers to understand).
The reason I ask is because I am not convinced that REST properly uses HTTP. For example in the following examples: 1. /product/12345/ 2. /product?id=12345 Option 1 is more RESTful but 2 is more HTTP "compliant" because that's how s are submitted by standard browsers. In jQuery you can even serialise a form's elements into an AJAX request and the result is a query string and not a path. To get REST URLs you would always need to manipulate standard URL formations which is extra code for no real benefit. Does REST completely ignore query strings or are they only for queries i.e. searching?
Upvotes: 1
Views: 263
Reputation: 1468
IMHO as far as REST is concerned there is absolutely no difference. In RFC 2396 there was a line
The query component is a string of information to be interpreted by the resource.
which was was later changed in RFC 3986 to be:
The path component contains data, usually organized in hierarchical form, that,
along with data in the non-hierarchical query component, serves to identify a
resource (Section 3.3)
So both are equivalent now but as you said
"aside from making the API easy for other developers to understand"
You sure don't mean to take this lightly, it should be the most important thing in any line of code you ever write
Upvotes: 3
Reputation: 32367
REST identifies the location of a resource - not the properties of that resource. So when you're submitting changes to an object to a REST API you can either post them or use a query string. There's not much of a practical benefit on the client, but it certainly makes the backend easier to test and manage.
Upvotes: 1