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
I use https://github.com/entomb/slim-json-api for my API written in Slim 2 to enable JSON-response. Init code looks something like this:
function APIRequests () {
$app = \Slim\Slim::getInstance();
$app->view(new \JsonApiView());
$app->add(new \JsonApiMiddleware());
}
$app->group('/api', 'APIRequests', function () use ($app) {
$app->get('/areas/:id', function ($id) use ($app) {
$app->render(200, Area::find($id));
});
});
I really like the abstraction level using middleware and grouping of routes, making it easy to apply different response types to different areas of the app.