Re: Redirect Without Changing URI

Erik Mogensen <[email protected]> Tue, 21 May 2013 23:23:25 +0200
Newsgroups gmane.comp.web.services.rest
Message-ID <CADbGZjZO5muoZGQ9swhVko_YU+faOOzAE8Fq3Fmmrj4-68WbgA@mail.gmail.com>
On Tue, May 21, 2013 at 6:40 PM, Shea Levy <[email protected]> wrote:

> **
>
> I recently ran into a situation where I had several pages that had the
> same content, but represented different states in the application due to
> where links from the page pointed. As an example, consider a game where
> you move from room to room, each room may have monsters to fight or
> items to pick up and may have any number of exits. You might have two
> rooms with the same contents and the same exits, but exiting north from
> the first room brings you to a different place than exiting north from
> the second.
>

Pardon my not answering the question, but wouldn't two rooms have two
different URIs even though they have the same contents?

e.g.
/room/red has <link href="room/blue" rel="north"/>
/room/white has <link href="room/orange" rel="north"/>

In a way, the rooms are not identical, as the north exit exits elsewhere.

In the same way, the current state of the application isn't the same if
invoking the "north" hypermedia control takes you to two different places.

If "north" takes you to two different places depending on something else,
Hypermedia is no longer the Engine of Application State. :-)


> My first thought on representing this would be to have each
> exit be a hyperlink with a relative URI, and respond to the request to
> get one of the identical rooms with a protocol-level redirect (to the
> same shared resource) that doesn't cause the client to change the
> meaning of relative URIs. Do any REST-capable protocols (the only one I
> know of is HTTP?) support this? Could they?
>

It sounds a bit strange, but I would have to re-read the definition of 302.
 You want e.g. to say you're in /room/red, which redirects 302 (temporary)
to e.g. "/places/redrum" — the client would "get" the representation of
"redrum" and resolve links in relation to "red" instead? so <link
href="blue"/> would resolve to /room/blue and not /places/blue.

I guess, if you consider the security constraints (think CORS in web
browsers) and you are writing media types, and don't mind talking about
HTTP when talking about your media type (see HTML[1]), you could say that a
302 response should leave the base URI unchanged, caveat in mind!

HTTP assigns a similar capability to the Content-Location header[2]: "The
value of Content-Location also defines the base URI for the entity."  This
has, however, been removed in the httpbis[3]: "The definition of
Content-Location has been changed to no longer affect the base URI for
resolving relative URI references, due to poor implementation support and
the undesirable effect of potentially breaking relative links in
content-negotiated resources."  YMMV.

PS: Have you seen this? application/maze+xml [4]

[1]: http://www.w3.org/TR/html5/infrastructure.html#resolve-a-url (bullet
#12)
[2]: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.14
[3]:
http://tools.ietf.org/html/draft-ietf-httpbis-p2-semantics-22#appendix-B
[4]: http://amundsen.com/media-types/maze/
-- 
-mogsie-