Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have a web application which I want to make RESTful. Here is the structure of the app:

  1. Top level has a bunch of search screens, they are basically tabs which search different parts of database with different parameters.
  2. After the search is done we display search results in a new tab, inside this tab is a table with a list of results.
  3. From the list of results we can drill down to individual details for each row (they also open in a new tab)
  4. Inside the details there are further additional details (and some sub-searches relevant to the the item). These additional details are also open in a new tab.

So, now I want to make this app RESTful - the goal is for people to share their searches and screens easily, have simpler URLs, get rid of some information stored in session.

  • Is this feasible for the design we have to make it RESTful?

  • The main difficulty I see is that we have multiple tabs with different searches and details, how do I reflect it in the URL?

  • Also, the search could be quite complex - users can enter 50 different filters and could enter multiple ids - up to a thousand at the same time. What would be a preferred solution in this case?

If this is not quite works, then is there a way to have several tabs that correspond to different URLs in one URL?

share|improve this question
2  
IMO search fits the query parameters model better than the REST model. I'd guess each different kind of search gets a different resource url, but the actual filters should be query parameters. –  CodesInChaos Feb 27 '13 at 18:06
    
I am sorry, I am not familiar with query parameters model - is it just storing query parameters somewhere? I can use combined approach (probably) and have a part of app (details and additional details) restful and just not populate the rest. The query then is how to have several URLs that correspond to several tabs? –  Roman Hoyenko Feb 27 '13 at 20:16
    
I believe by query parameter model the author means adding the different query elements to the URL when making a request. i.e. search?startswith=Joe&OlderThan=5&YoungerThan=30 etc... –  Mike Feb 27 '13 at 20:27

2 Answers 2

up vote 1 down vote accepted

As I have understood your question you have to make your application aware of a series of open tabs (0 or more) and of a series of search parameters. Because a restful approach requires a finite amount of parameters and a url length not exceeding 2000 characters (see restful max url length) you have to somehow store your data in the database, assign an id and use this id in your restful application instead of the whole string length.

You therefore will first make each possible tab restful

http://myapplication/search/query=something
http://myapplication/parameters/bgcolor=fff
http://myapplication/credits/user=john.doe

Then you create two tables in the database where you have a many to one relation with your parameters, where the one side represents your final URL and the many side represents the series of tabs.

For instance

CREATE TABLE RESTFUL_PAGE (INT id, VARCHAR page_name, PRIMARY KEY id);
CREATE TABLE RESTFUL_TABS (INT id, VARCHAR url, PRIMARY KEY id, FOREIGN KEY id REFERENCES RESTFUL_PAGE.id);
share|improve this answer

The first step in developing any REST service is identifying what kind of resources you are going to expose.

As far as I can tell, you have a few kinds of resource:

  • Tables of search results
  • Detailed views of records
  • Collections of mixed queries and detailed views (each user's set of "tabs")

Every kind of resource should have a URL. But what goes into your URL is not important, as long as it is unique to that resource.

Since its infeasible in your case to put all of the parameters which identify your resources into the URL, you are going to have to generate unique ids and store the parameters in a look-up table somewhere. Or you could mix both strategies:

http://myapplication/users/johnsmith/tabs
http://myapplication/query/AJEL32339?page=1
http://myapplication/details/9383721

Once you have URLs for your resources, sharing results is easy - just provide a 'Share these results' button with the URL for those results. If somebody visits a results or details screen directly, offer to add it to their personal collection of tabs.

share|improve this answer
    
Please read what REST actually means - the first step is creating a state machine for the application, in which each state transition is represented by a resource which is linked from the representation of the previous state ( hence REST - Representational State Transfer). So the first step is to create the sequence of states, not determine kind of resources. REST is not about creating a nice permalink. –  Pete Kirkham Feb 28 '13 at 14:18
    
I know what REST means. How do you determine your state machine without first identifying what resources are participating in it? –  ajlane Mar 1 '13 at 2:37
    
From user stories. The state machine represents the user's interactions with the application; you're talking about formatting urls to the results of those interactions which is a later stage. –  Pete Kirkham Mar 1 '13 at 15:33
    
I think we're largely of the same mind. I would define resources, then describe how they interact with clients (and each other). My answer focused on URLs because that seemed to be the main concern of the question. –  ajlane Mar 3 '13 at 10:52

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.