Re: RE: Handlers for search urls
FWIW, one thing that I like is to think of query parameters as "adjectives" that modify the meaning/interpretation of the noun or as "adverbs" modifying the action. Hope this helps, John On 11/5/06, Jerome Louvel <[EMAIL PROTECTED]> wrote: Hi Vincent, > Well, it turns out restlets only understand the base of the URLs. The choice of not exposing the query string and the fragment part of the target resource URI was deliberate. The reason is that the query string is often composed of a sequence of parameters ("key=value") that can appear in any order while keeping the same semantics. /accounts?balance_less_than=2000&status=active is equivalent to: /accounts?status=active&balance_less_than=2000 So, we encourage developers to deal with the query part inside the Handlers (or using the ExtractFilter, to be renamed Extractor) using the Form class (via getQueryAsForm() method). Thanks, Jerome
Re: Handlers for search urls
> attach("/accounts/[0-9]", new GetAccountHandler()) > attach("/accounts", new SearchAccountHandler()) Yes, that's what I ended up doing. It's a good solution. Thanks. Vincent.
RE: Handlers for search urls
It wouldn't be an issue because when encode all reserved characters when creating the actual regex pattern. Best regards, Jerome > -Message d'origine- > De : news [mailto:[EMAIL PROTECTED] De la part de Vincent > Envoyé : dimanche 5 novembre 2006 20:55 > À : discuss@restlet.tigris.org > Objet : Re: Handlers for search urls > > > > Just a thought: could it be because "?" is a valid regexp meta- > > character ( > > No, it's not the issue. > > -Vincent.
RE: Handlers for search urls
Hi Vincent, Here is the official structure of a generic URI: URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ] So, as we define patterns on the hierarchical part, the question mark is not considered. To come back to your initial question, instead of defining: attach("/accounts/[0-9]+$", new GetAccountHandler()) attach("/accounts?[.]+$", new SearchAccountHandler()) You could define: attach("/accounts/[0-9]+$", new GetAccountHandler()) attach("/accounts$", new SearchAccountHandler()) Actually, even this should work as we select the route that matches the largest percentage of characters in each pattern: attach("/accounts/[0-9]", new GetAccountHandler()) attach("/accounts", new SearchAccountHandler()) Doesn't that solve your problem? Best regards, Jerome > -Message d'origine- > De : news [mailto:[EMAIL PROTECTED] De la part de Vincent > Envoyé : dimanche 5 novembre 2006 19:50 > À : discuss@restlet.tigris.org > Objet : Re: Handlers for search urls > > Hi Jerome, > > > > The choice of not exposing the query string and the > fragment part of the > > target resource URI was deliberate. > > The question is: is the question mark part of the query string? > > > The reason is that the query string is often composed of a > sequence of > > parameters ("key=value") that can appear in any order while > keeping the same > > semantics. > > Agreed. I wasn't trying to define a regexp on the request > parameters, I was > just interested in catching the question mark. I wanted to > differentiate > between '/accounts/123' and 'accounts?status=active'. > It turns out that attach("/account/[0-9]+",..) and > attach("/accounts[.]+",...) > does the trick, but attach("/accounts?[.]+",...") would have > been slightly more > elegant. > > -Vincent. >
Re: Handlers for search urls
> Just a thought: could it be because "?" is a valid regexp meta- > character ( No, it's not the issue. -Vincent.
Re: Handlers for search urls
On 5 Nov 2006, at 18:49, Vincent wrote: Hi Jerome, The choice of not exposing the query string and the fragment part of the target resource URI was deliberate. The question is: is the question mark part of the query string? The reason is that the query string is often composed of a sequence of parameters ("key=value") that can appear in any order while keeping the same semantics. Agreed. I wasn't trying to define a regexp on the request parameters, I was just interested in catching the question mark. I wanted to differentiate between '/accounts/123' and 'accounts?status=active'. It turns out that attach("/account/[0-9]+",..) and attach("/accounts [.]+",...) does the trick, but attach("/accounts?[.]+",...") would have been slightly more elegant. Just a thought: could it be because "?" is a valid regexp meta- character (it may mean 'zero or one'). Did you try any escapes like "/ accounts\?[.]+". Also, if "[]" means 'character class' then surely "[.]+" and ".+" are identical? I hope this helps as I haven't check the docs for the exact regexp language it uses. Ta, -- dahdah didi dahdidah di http://wiki.houseofmoran.com/
Re: Handlers for search urls
Hi Jerome, > The choice of not exposing the query string and the fragment part of the > target resource URI was deliberate. The question is: is the question mark part of the query string? > The reason is that the query string is often composed of a sequence of > parameters ("key=value") that can appear in any order while keeping the same > semantics. Agreed. I wasn't trying to define a regexp on the request parameters, I was just interested in catching the question mark. I wanted to differentiate between '/accounts/123' and 'accounts?status=active'. It turns out that attach("/account/[0-9]+",..) and attach("/accounts[.]+",...) does the trick, but attach("/accounts?[.]+",...") would have been slightly more elegant. -Vincent.
RE: Handlers for search urls
Hi Vincent, > Well, it turns out restlets only understand the base of the URLs. The choice of not exposing the query string and the fragment part of the target resource URI was deliberate. The reason is that the query string is often composed of a sequence of parameters ("key=value") that can appear in any order while keeping the same semantics. /accounts?balance_less_than=2000&status=active is equivalent to: /accounts?status=active&balance_less_than=2000 So, we encourage developers to deal with the query part inside the Handlers (or using the ExtractFilter, to be renamed Extractor) using the Form class (via getQueryAsForm() method). Thanks, Jerome
Re: Handlers for search urls
Sean, > We had a similar issue and I think this is an area where the REST philosophy > is somewhat stressed. < [..] > We decided to make a web service, use a POST and put the criteria in the > XML. Then the URI could be /accounts/search which is pretty easy to > deal with. I'm not sure it stretches the REST philosophy. POSTing a search criterion makes sense if you want to cache a cursor on the server side, for instance. You could do this: POST /accounts/search balanceLesstThan=2000 status=active The serve returns: http 2001 created location:/accounts/cursor/121212 The server keeps the open cursor in the cache for a limited amount of time. You access it with: GET /accounts/cursor/121212?page=2 This is on the salesforcers.com search API works. -Vincent.
Re: Handlers for search urls
Hi Vincent, Vincent yahoo.ca> writes: > > Hi Piyush, > > > /accounts/search/less_than/1 > > /accounts/search/greater_than/1 > > /accounts/search/between/1/2 > > The issue I have with this approach is that it doesn't allow to mix several > search criteria (balance_less_than=2000&status=active). > > I'd like to have: > 1) /accounts/1234 -> retrieve an individual account > 2) /accounts?balance_less_than=2000&status=active ->search > > That's why I was hoping creating my restlets like so: > attach("/accounts/[0-9]+$", new GetAccountHandler()) > attach("/accounts?[.]+$", new SearchAccountHandler()) > would work. > > Now, following your idea, I could do: > attach("/accounts/search?[.]+$", new SearchAccountHandler()) > > and access it with /accounts/search?balance_less_than=2000&status=active > > But it kind of bothers me to have to have to specify the action twice (the > http > GET method and the 'search' portion of the url). > > > and restlets that support that class because they > > understand the URLs .. > > Well, it turns out restlets only understand the base of the URLs. We had a similar issue and I think this is an area where the REST philosophy is somewhat stressed. We thought of putting the search criteria on the URI but in our case, we could easily overrun the length restrictions because we have so many criteria. We decided to make a web service, use a POST and put the criteria in the XML. Then the URI could be /accounts/search which is pretty easy to deal with. I'd be interested in hearing more on this topic. Sean > -Vincent. > >
Re: Handlers for search urls
Hi Piyush, > /accounts/search/less_than/1 > /accounts/search/greater_than/1 > /accounts/search/between/1/2 The issue I have with this approach is that it doesn't allow to mix several search criteria (balance_less_than=2000&status=active). I'd like to have: 1) /accounts/1234 -> retrieve an individual account 2) /accounts?balance_less_than=2000&status=active ->search That's why I was hoping creating my restlets like so: attach("/accounts/[0-9]+$", new GetAccountHandler()) attach("/accounts?[.]+$", new SearchAccountHandler()) would work. Now, following your idea, I could do: attach("/accounts/search?[.]+$", new SearchAccountHandler()) and access it with /accounts/search?balance_less_than=2000&status=active But it kind of bothers me to have to have to specify the action twice (the http GET method and the 'search' portion of the url). > and restlets that support that class because they > understand the URLs .. Well, it turns out restlets only understand the base of the URLs. -Vincent.
Re: Handlers for search urls
Honestly there are many ways you could solve this ... I would create /accounts/search/less_than/1 /accounts/search/greater_than/1 /accounts/search/between/1/2 And then you could either have a generalised Serach restlet ... or you could have restlets handling each search case individually ... I would have a search class that actually does the heavylifting of seaching balances.. and restlets that support that class because they understand the URLs .. I hope I was clear enough Cheers Piyush
Handlers for search urls
Hi all, What would be the best approach to attach a handler to search urls (i.e. urls of the form '/accounts?balance_less_than=1')? My first attempt was to attach the handler to "/accounts\\?[.]+", but this doesn't work as the pattern matching is done on request.getRelativePart() ('/accounts', in this case), so the handler is never called. Is my only option is to attach the handler to "/accounts[.]+", and to analyse the request parameters in the handleGet method? Thanks, -vincent.