Hi all.


I am building an application that will be used both by humans and machines ("via an API") and I am making it RESTful. I've decided to design it as one big API where human-operated browser is just another client to the API. With that I'm actually mixing user interface and data in requests for certain resources.

For example, a list of profiles sits behind the /profiles URI.

If requested format is HTML (default), the the list of profiles is returned as full HTML page complete with navigation links, sidebar content, etc... It's a classic interface webpage. If requested format is JSON (via Accept header, or ?format=json query), only the data is returned as JSON array of profile dictionaries

The most obvious benefit here is that for each resource I basically have single view handler (with the exception that POST/PUT and DELETE call respective functions after the resource view handler has "prepared" the resource in a way that's common to all verbs), and what is returned back to client is only a matter of Renderer and template. The HTML renderer uses templates that "know" how to include this additional data (nav links, sidebar content, etc...)

So I have a single set of resources and only the requested format defines whether the entire interface is sent back along with data for humans and their puny browsers. Machines of course do not need all that and talk in simple and effective JSON, but basically I have just one set of view handlers.


However, I'm having a philosophical discussion with myself here whether this is "truly" RESTful and whether I'll hit some kid of unforeseen obstacle later.


Because the only alternative is separating "interfaces" (complete HTML pages with navigation, sidebar content, blah) as different resources which may or may not contain the data (ie. is it already present in the page or must be requested with some background javascript magick against the "real API"). While this does provide a cleaner separation of concerns, I'm forced to have more view handlers for basically the same thing because interface and its data are interconnected, there's no generic interface here that can operate on different data, etc...

Or perhaps I can separate the URIs and have the interface view handlers be just dummy functions that delegate to the actual API view handlers.



Opinions? Suggestions?


--

.oO V Oo.

--
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to