Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

How can I serve JSON and XML data, like Vanilla does with Categories?

edited July 2012 in Vanilla 2.0 - 2.8

I noticed that, with many pages in Vanilla, it's possible to simply add ".xml" or ".json" and have the page content returned in these formats (e.g. http://localhost/vanilla/categories.json). I'm trying to achieve the same with a plugin, but I'm having difficulties. As I expected, to request JSON or XML data it's not just a matter of adding a suffix. In my case, I create a Controller_MyPlugin() method, but I can't simply call http://localhost/vanilla/myplugin.json and get back Json data. So, first question is how do I "receive" these requests?

Once the JSON/XML request arrives, I guess I'll have to use a switch statement to choose what to render, but I'm not sure of this either, as "categories" controller doesn't do it.

Thanks in advance for the answers.

Comments

Sign In or Register to comment.