3 ms·
RESTful API and a Web Site in the Same URL
- stephenr 12y agoI'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 12y agoExactly! 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.