

RESTful API and a Web Site in the Same URL - yegor256a
http://www.yegor256.com/2014/09/09/restful-web-sites.html

======
stephenr
I've taken this approach for a long time now - not only does it mean less work
overall, it means none of this "the API now supports feature X that the Web UI
has supported for 4 months" \- they are the same codebase and thus parity is a
given.

-Edit I don’t mean this specific implementation using XSLT, I mean serving html, xml, json, csv, etc data from the same url -/Edit

The article makes mention of using XSLT (which basically means your "api" is
only usable as XML) but it's so much simpler than that.

This type of thing is _exactly_ what the HTTP Accepts header is for. The
client says it accepts "application/json" you return a json encoded result.
The client says it accepts "application/xml", you send an XML result. The
client says it accepts text/html, you send an HTML result.

~~~
yegor256a
Exactly! I didn't mention that in the article, but, of course, the format of
the output depends on the Accept HTTP header. I'm using mostly Java, and
JAXB+JAX-RS helps to switch between formats without touching the data.

