How can I serve JSON and XML data, like Vanilla does with Categories?
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
wouldn't you just call the
http://vanillaforums.org/categories/questions/feed.xml
http://vanillaforums.org/categories/questions/feed.json
http://vanillaforums.org/categories/questions/feed.rss
based on an event and store and process results.
within the plugin and set up the plugin the usual way.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
@peregrine I actually need to serve my own data, not the categories. Loading and returning the data is not the big deal, the issue is receiving the request for Json.
The issue I'm having now is the following: if call http://localhost/vanilla/myplugin/mycontroller, method Plugin_MyController is executed, as expected. If I just append .json (i.e. http://localhost/vanilla/myplugin/mycontroller.json), the request gets handled by the Index controller of the plugin, as if MyController were not found.
My shop | About Me
here's to hoping x00 will come to the rescue. . Looks like another interesting discussion.
I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.
Times like this i feel like im 3ft tall !
There was an error rendering this rich post.
Sorry for the (possibly) stupid question: what does it mean?
My shop | About Me
Means : the question is right over my head
There was an error rendering this rich post.