Loading ...
Sorry, an error occurred while loading the content.

5012The role of queries in REST?

Expand Messages
  • Roger L. Costello
    May 6, 2005
      Hi Folks,
       
      My question is with regards to the role of a Web site in supporting queries.  Let me give an example to demonstrate what I mean.
       
      Suppose that a Web site implements this "hierarchical model of resources" for a bombing mission:
       
      Mission
          Plan1
               ...
          Plan2
              Aircraft
                  AA36
                      ...
                  BB06
                      Payload
                          Bomb1
                              ...
                          Bomb2
                              Fuze5
       
      By implementing this hierarchy the Web site gives users the ability to get any resource by simply composing a URL, where "/" is used to express a parent-child relationship in the resource hierarchy.  For example, to obtain the AA36 aircraft resource in Plan2 the user issues this URL:
       
       
      This is, of course, standard REST.
       
      Now consider this problem: how would the Web site support the many kinds of queries that a user might want to make, e.g.,
       
          "Tell me all the Aircraft that carry Bomb1"
       
      The first approach that comes to mind is for the Web site to make available a "form" that the user can retrieve, fill in, and return.  The Web site parses the form to extract the query, processes it, and returns the results to the user.
       
      However, there is a problem with this approach.  There are virtually infinitely many different kinds of queries that  users may want to make.  How can a Web site possibly provide a form for every conceivable kind of query?  It would be impossible to anticipate every kind of query that users might want to make.
       
      More importantly, I believe that focusing on "forms" is missing the point of REST.
       
      Let me now restate my original question:
       
          What is the role of queries in a REST-based system?  How can a Web site give
          users the ability to retrieve the kinds of custom data that they desire?  
          How are queries done in a RESTful manner?
       
      Below are some thoughts that I have on this issue. 
       
      I believe that the REST model can be simply summed up as:
       
           "A Web site is composed of resources.  A Web site should provide a URL to  
            each resource and enable the exchange, updating and deleting of resources". 
       
      Thus, with REST it is always an exchange of resources and nothing else.
       
      So when we start talking about a user filling in a form we are either talking about a "form resource" or we are breaking away from the REST model.  If we are talking about a "form resource" then how would it fit into the above mission resource hierarchy?
       
      I believe that it is not appropriate in REST to talk about forms.  Instead, we should talk about resources. 
       
      I believe that with the REST model the idea of issuing queries doesn't make sense.  With REST we exchange resources, not queries.
       
      That said, I understand the desire to enable a user to query to a Web site for information such as "what aircraft carry Bomb1?". 
       
      One solution is: this is a user processing issue, not a Web site resource issue, so it is outside the scope of REST.  In other words, if a user wants to know what aircraft carry Bomb1 then it is up to the user to retrieve each aircraft resource and do processing on each aircraft resource to determine if it carries Bomb1.
       
      That's not a particularly satisfying solution.  Perhaps there a way to rephrase the question so that it involves an exchange of resources, rather than a query exchange?   
       
      I would appreciate hearing your thoughts on this issue.  /Roger
    • Show all 20 messages in this topic