views:

38

answers:

2

I am having a problem with my current RESTful api design.

What I have is a REST api which is consumed by Django web-server, which renders the HTML templates.

    REST api 
        > Django webserver
                 > HTML

The problem I am encountering is that I have to reconstruct all the URLS like

mysite.com/main/cities/<id>/streets/

into equivalent rest api urls on my web-server layer:

api.com/cities/<id>/streets/

Thus I have a lot of mapping back and forth, but as far as I know REST says that the client (in this case my web-server) should NOT need to know how to re-construct the urls.

Can REST be used for such a setup and how? Or is it only viable for Server-Client architecture.

Thanks

A: 

Why don't you let the web server rewrite the URLs?

Bernd
hows that? Do you mean just mapping for example?
drozzy
well, forgive my simplicity. You say that you need to reconstruct your URLS and thats something usually the web server can take care of. That basically would be removing the "/main" from the URLs to make them compatible to your REST client.
Bernd
It's not always one-to-one mapping. My REST service might provide a list of resource 100-items at a time, while I may display them on the HTML client 50 items at a time. I have to do more involved conversion than that.
drozzy
A: 

I think what you are trying to do is really quite tricky. Assuming your web server is using HTTP properly (e.g. no session state) you are actually trying to layer one REST service on top of another REST service. This means that you have "application state" at the web server level that you need to transfer down to the client and manage along side the actual client state. My head hurts thinking about it.

I have not seen this type of REST service composition done much. However, Ceasare Pautasso has a research paper on it here. In his case he is going a step further and using two REST services to create a third composite service.

Darrel Miller
Thanks for the comment. My head hurts too :-) Also note - that I am not trying to create a RESTful service from my intermediary web-server (django) to the html client (browser). Only trying to be a kind of "mediator" in between them. PS: Great paper so far. I'll continue reading and see what it recommends.
drozzy
Hm... I must say that paper is nothing more than exploration of "how to do rest composition with this cool java tool". I would much rather have read the general philosophy behind it vs. drag this icon into eclipse and create a bunch of arrows. Thanks anyways - it was an interesting read.
drozzy
Sorry about that. I assumed the paper would be a bit more than that. I just heard Ceasar speak at the WS-REST conference and he did a decent job of covering the subject.
Darrel Miller
I realize that you are not explicitly trying to create a REST service with your web server, but you probably are creating one unintentionally. You are conforming to the uniform interface, you are using standard media types that support hypermedia, your messages are self descriptive and all of your resources (web pages) are identified with URIs. As long as you avoid session state, web sites are naturally RESTful.
Darrel Miller