Search the web
Sign In
New User? Sign Up
rest-discuss · REST Discussion Mailing List
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
URL-Design: Structured Resources vs. Searching Globally   Message List  
Reply | Forward Message #9713 of 14029 |
Re: [rest-discuss] URL-Design: Structured Resources vs. Searching Globally

On 10/30/07, Stefan Hübner <sthuebner@...> wrote:
> Hi all,
>
> I'm designing an API which exposes data like companies, products, etc..
>
> To access company-data the API defines URLs like this
> "/companies/<id>", and for product-data URLs look like this
> "/products/<id>". This way I can search for companies with a URL like
> this "/companies?name=<pattern>" or for products with URLs:
> "/products?name=<pattern>".
>
> Then I thought, products actually belong to the companies producing
> them. So I came up with this product-URL:
> "/companies/<comp-id>/products/<prod-id>".
>
> But here's my problem now: how should a search be designed which is to
> search among all products of all companies - a global product search
> that is? "/companies/<comp-id>/products?name=<pattern>" doesn't work
> globally - at least it shouldnt.
>
> Am I to expose something like "/search?type=products&name=<pattern>"
> or are there reasonable alternatives?
>
> Or am I better off with the first approach?
>
>
> How would you design such an API?
>



You don't say this explicitly, but it sounds like "designing an API"
means, you are designing a formula that programmers of client programs
can use to construct a query url.

If that is what you mean, well, I wish we'd do less of that.

The form of a query url should only be important to the server
implementor. The server should deliver an HTML form or Xform or some
such, that tells the client to fill in some blanks, and then using the
rules of HTML forms, the client composes the URL.

When you do that, it won't matter if you decide for queries the one
way, then three weeks later decide to do it the other way, or some
third way.

If this is machine to machine communication, it amounts to telling
developers to look for <input> elements named "product-id" and to form
the url according the rules of the forms language, e.g. append
"?name=value..." to the form's action attribute.

I admit I'm not sounding very convincing with this argument, because
I'm asking you a) to have clients make an extra GET first to retrieve
the form, and b) they still have to have some foreknowledge of the
element name attributes they should understand. It does however
insulate them from having to understand the form of your urls.

I guess I'm putting this out here for discussion, and not really
suggesting you implement it this way. But if anyone out there thinks
there's a good way to do what I'm trying to do, which is to drive the
interaction through forms, please jump in.



Hugh



Wed Oct 31, 2007 11:05 pm

hwinkler99
Online Now Online Now
Send Email Send Email

Forward
Message #9713 of 14029 |
Expand Messages Author Sort by Date

Hi all, I'm designing an API which exposes data like companies, products, etc.. To access company-data the API defines URLs like this "/companies/<id>", and...
Stefan Hübner
sthuebner@...
Send Email
Oct 30, 2007
6:18 pm

... I see nothing wrong with having both options -- i.e. /products is the collection resource for all products, and /companies/{id}/products is the...
Stefan Tilkov
stilkov
Offline Send Email
Oct 30, 2007
6:42 pm

On 30/10/2007, Stefan Tilkov <stefan.tilkov@...> wrote: [snip] ... OK. So /products would return e.g. XML like <products> <product...
Stefan Hübner
sthuebner@...
Send Email
Oct 31, 2007
10:35 pm

... Yes, or it could be <product xlink:href="/products/1" /> or <product xlink:href="/AD5EFFAE132865DDE" /> or whatever. ... Exactly! ... It's tempting to...
Stefan Tilkov
stilkov
Offline Send Email
Nov 1, 2007
9:32 am

... You don't say this explicitly, but it sounds like "designing an API" means, you are designing a formula that programmers of client programs can use to...
Hugh Winkler
hwinkler99
Online Now Send Email
Oct 31, 2007
11:05 pm

... I *would* suggest that it is implemented that way. It’s the hypermedia constraint. Truly RESTful apps are – by definition![1] – designed around the...
A. Pagaltzis
a22pag
Offline Send Email
Nov 1, 2007
11:52 am

... Yeah, not sounding terribly convincing to me. I do think your described solution is fine, as long as there really isn't a need for 'machine to machine'...
Patrick Mueller
pmuellr
Online Now Send Email
Nov 1, 2007
1:17 pm
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help