tags:

views:

174

answers:

1

If I have to create a URL in my RESTful web service, which would be used by my clients to search all businesses by their fields where the fields are optional, what would the URL look like?

A business can be search by their name alone, name and phone number or name, phone number and contact e-mail.

+4  A: 

Chandru, think of the list of all the businesses like of a set of entities with attributes. You can create URIs that identify (select) a subset by the use of parameters in the URI.

Commonly this is done by query string parameters (the stuff after the '?') but you can also specify parameters as path segments or matrix URIs.

The most typical means to do this would be something like

It is conceptually similar to an SQL select clause.

Parameters in path segments or matrix parameters have an impact regarding the indexing possibilities (e.g. matrix parameters allow you to filter at multiple levels because the hierarchy can continue after wards, which it cannot with query parameters). I suggest you make that a different question if you are concerned with it.

Example:

http://foo.org/service/businesses/france/name=acme;city=paris/latest/?contact=xxx

Jan

Jan Algermissen
Aren't using query strings non-RESTy?
Chandru
@Chandru Using query strings parameters is perfectly valid. The resource you are looking for is a list of businesses, which Jan has identified using '/foo.org/service/businesses'. Which businesses appear in that list is controlled by the query parameters.
Darrel Miller
No, not at all. What is important with regard to RESTfulness is that the parameters are specified and do not depend on some out-of-band knowledge between client and server. Also, the client must be instructed at runtime how to 'populate' the parameters (e.g. via forms or link templates).Take a look at http://www.opensearch.org as an example of an extensible form mechanism.However, do not worry too much about this in the first step. Subscribe to rest-discuss on yahoo groups and ask for clarification over there as the topic is more 'verbose'.
Jan Algermissen
I hope i wasn't unclear: "No, not at all" referred to you "Aren't". So, to clarify: Yes, using query string parameters is perfectly valid. Just as Darrel said. Doh - better to be explicit.
Jan Algermissen
Thanks for the detailed explanation and pointing me to the group.
Chandru