Serving HTML application pages and JSON data in REST -


in restful application, idea use "resource" url serve both json data , page access data? if not, how should differentiate 2 things?

suppose have page /routes , have page list routes. should this:

html page

get /routes accept: text/html  response: <h1>routes</h1> <p>blah blah blah</p> ... <table></table> <script>     $.getjson('/routes').done(insertdataintotable); </script> 

json response

get /routes accept: application/json  response: [     {"number": "95", "start": "place d'orléans", "end": "barrhaven centre"},     {"number": "96", "start": "hurdman", "end": "kanata"},     {"number": "97", "start": "bayshore", "end": "airport/aéroport"},     /* etc... */ ] 

this seems wrong because 2 requests same url/uri, return different resources (one application page whereas other data). seem more appropriate serve accept: text/html:

get /routes accept: text/html  response: <table>     <thead>         <tr><th>number</th><th>start</th><th>end</th></tr>     </thead>     <tr><td>95</td><td>place d'orléans</td><td>barrhaven centre</td></tr>     <!-- etc... --> </table> 

(which wouldn't not useful.)

i've thought several options:

  1. use http accept header described above
  2. use query parameter (e.g. /routes?type=html)
  3. use different path pages (e.g. /routes data , /pages/routes application)
  4. use extensions (e.g. /routes data , /routes.php application)

1 , 2 not seem quite right. i'm not keen on 3 though page resource itself, doesn't represent entity in application. option 4 looks plain ugly.

i've tried looking @ major sites , of them serve data different host/subdomain (examples: facebook.com / graph.facebook.com, twitter.com /api.twitter.com) , isn't option me.

any ideas? question shouldn't opinion-based references appreciated.

number 4 looks best option, since html page different type of resource resources in api. seems idea separate pages api resources.
examples twitter , facebook support approach.


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -