I am using the Slim framework with PHP to create a RESTful API for my app. However, I assumed that the framework would have some way of creating easier JSON outputs rather than just exit($jsonEncodedVariable);.
Am I missing something in the framework, or do I need to use json_encode()… exit($json)… for every method?
All of the data is taken out of the my MySQL database and would then be put into a JSON array depending on what REST request was called.
For example, if /api/posts/all was requested, I would exit() a JSON array of all the posts which each value for its own key, "value" : key.
My question is, is there an easy way, using the slim framework, for exit()‘ing JSON code instead of exiting it as plain text?
Hint: Using The Slim PHP Framework for Developing REST APIs