Using Query String in REST Web Services -


i thought 1 main characteristic , reason using rest web services use path parameters rather query parameters. many publicly available rest web services use query parameters.

am wrong in thinking query parameters not supposed used in rest web services? there recommendation or rule not using query parameters in rest web services?

the query string can still used in rest web services not in same way normal.

you have think of url key resource. url unique identifier resource. example

http://example.com/products/123   -- 123 id of products. 

accessing /products return full list of products. adding id return specific product.


the problem using slashes every filter

what if want order product in specific way?

http://example.com/products/united-states 

well, there ambiguity @ first look. united-states id? ambiguity can solved saying id represented \d+. correct.

ok our first parameters made of words country.

now lets want add more filters, lets try , add more slashes.

http://example.com/products/united-states/home/asc 

but don't want united states products only! still want home products.

http://example.com/products/home/asc 

wait... home country? i'm not sure now, it's kind of ambiguous... , if want add filter tomorrow? do... add more slashes?

the url becomes cluttered , full of ambiguous parameters optional @ first , become obligatory because of ambiguity.


my advice

the correct way, me, use query string thing specific query. because, can sort query in way want, still same query. query products.

so form should like

http://example.com/products -- products http://example.com/products/{id} -- specific 1 http://example.com/products/?country=united-sites -- filtered 

this way can add new filters anytime want , keep urls clear , won't ever break though change filters.


more information

if want more information really, advise look @ this conference david zülke, guy working symfony framework. talks lot of things of rest web-services, talk urls, , how build them (mainly 16 30 minutes).

you can @ apigee website. have lot of videos (and books) rest. more this video, on topic here.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -