$name = $request['name']; $db = new Ingredients(); $item = $db->add_ingredient($recipe_id, $name); if ($item) { // if successful, just return the JSON sent for use on the client-side $results = array('id' => $item, 'recipeId' => $recipe_id, 'name' => $name); $app->response()->header('Content-Type', 'application/json'); echo json_encode($results); } }); // PUT route $app->put('/ingredients/:id', function ($id) use($app) { $request = (array) json_decode($app->request()->getBody()); $name = $request['name']; $db = new Ingredients(); $items = $db->update_ingredient($id, $name); if ($items) { // if successful, return the new object with the values $results = array('id' => $id, 'name' => $name); $app->response()->header('Content-Type', 'application/json'); echo json_encode($results); } else { $app->response()->status(500); } }); // DELETE route $app->delete('/ingredients/:id', function ($id) use($app) { $request = (array) json_decode($app->request()->getBody()); $db = new Ingredients(); $items = $db->delete_ingredient($id); if ($items) {