Maybe I misunderstand but it's pretty trivial to render different server side output based on context and is common in most frameworks.
Just pass a header for request content type json. Then the server returns data in json format as opposed to html.
Just pass a header for request content type json. Then the server returns data in json format as opposed to html.