} else { $app->response()->body(json_encode($TeamModel->getError())); $app->response()->status(400); } }); $app->delete('/teams/:id', function ($id) use($app) { // Instantiate Team and set id attribute $TeamModel = new TeamModel(); $TeamModel->setId($id); // Delete team, respond with error if method returns false if (!$TeamModel->delete()) { $app->response()->body(json_encode($TeamModel->getError())); $app->response()->status(400); } }); $app->post('/teams/', function () use($app) { $requestJson = json_decode($app->request()->getBody(), true); // Instantiate Team and fill attributes $TeamModel = new TeamModel(); $TeamModel->setCity($requestJson['city'])->setName($requestJson['name']); if ($TeamModel->create()) { $app->response()->body(json_encode($TeamModel->toArray())); } else { $app->response()->body(json_encode($TeamModel->getError())); $app->response()->status(400); } }); /** * Launch application */ $app->run();