3

I have deployed a simple REST based application in RAD.

A simple URL is accessed using http://localhost/<contextroot>/users/<username> where <username> is accessed using reqeust.getAttributes(). Now, how do i pass more than one attribute to the REST service?

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
Subramanian
  • 5,552
  • 5
  • 25
  • 24

2 Answers2

3

Usually you'll use query parameters:

http://localhost/<contextroot>/users/<username>?a=10&b=hello

You haven't indicated which language or framework you are using so I can't tell you how to do this in code.

Marcelo Cantos
  • 181,030
  • 38
  • 327
  • 365
  • Also, you can use the URI path, depending on what the parameters *mean*. If you need more than just query parameters, it should probably have been a POST request. – S.Lott Mar 31 '10 at 11:52
  • thanks for the quick response. I use Java / J2EE with RAD / Restlet framework. The purpose is to do a Search operation. Allow a "like" Search to be done. There is a need to pass "%" with query parameters. – Subramanian Mar 31 '10 at 12:15
  • @Subramanian: "There is a need to pass "%" with query parameters". So? You encode query parameters to escape special characters like that. Search for "Encoding Query Parameters" for examples. – S.Lott Mar 31 '10 at 12:18
  • As much as I like query parameters, most REST implementations don't use them. – Scott Tesler Aug 13 '13 at 17:20
  • @ScottDavidTesler: I agree; query parameters are problematic for REST semantics. But I don't see any way around it in this case. The "clean" solution would be to access each attribute individually — `…//a` and `…//b`, but that's a nightmare for throughput, latency and backend load. HTTP keep-alives might alleviate the first two, but, without some clever delay-batching, the frontend is still lumbered with issuing multiple separate transactions to the backend. REST is a great paradigm, but it's not a panacea, I'm afraid. Sometimes, it just gets in the way. – Marcelo Cantos Aug 13 '13 at 22:53
0

You could also use URLs of the style http://localhost/<contextroot>/comments/<username>/after/<date>, but that tends to get messy if you wish to include a large number of options.

Christopher Creutzig
  • 8,656
  • 35
  • 45