Note that there are some explanatory texts on larger screens.

plurals
  1. POREST Hypermedia API - Navigating from Stateless Client
    text
    copied!<p>A straightforward question: if I am building a stateless client, which 'changes page' between requests, how do I properly consume a hypermedia API?</p> <p>A key point of course is that the client should not construct URLs. If we were to for example fetch a collection of some kind (let's say fruits), each collection entry would feature a URL to link to the individual fruit resource in the API. Great.</p> <pre><code>[ { "name": "Apple", "url": ".../fruits/15" } ] </code></pre> <p>However in my client, after presenting a list of fruits, I wish to link the list through to a different front-end page with details for the fruit. Such a details page should of course be bookmark-able, etc. The precise structure of the front-end URL is I realise, philosophically, of little concern - but it is of practical interest to the question below.</p> <pre><code>&lt;a href="?"&gt;Apple&lt;/a&gt; </code></pre> <p>The question then is, upon loading a fruit details page, how does the client with no current context decide on the API URL to GET?</p> <pre><code>/my/frontend/stuff/fruits/{?} </code></pre> <p>Now what :o?</p> <p>A solution which initially springs to mind is to have an 'item' URL template in the collection response, and to use the named parameter(s) therein to construct the page URL. The details page would then query the API to recover the same 'item' URL and implant the parameter(s) it was passed. This doesn't seem ideal, however it does achieve the desired decoupling.</p> <p>Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload