$app->response()->header('Content-Type', 'application/json'); echo json_encode($tasks); }); /* HTTP GET http://domain/api/tasks/1 RESPONSE 200 OK { "id": 1, "description": "Learn REST", "done": false } RESPONSE 204 NO CONTENT */ $app->get('/tasks/:id', function ($id) use($app) { $task = TaskService::getById($id); if ($task) { $app->response()->header('Content-Type', 'application/json'); echo json_encode($task); } else { $app->response()->setStatus(204); } }); /* HTTP POST http://domain/api/tasks REQUEST Body { "description": "Learn REST", } RESPONSE 200 OK Body