"status" => false, "message" => "Song id $id does not exist" )); } }); /* ---------------------------------------- */ // Fragments /* ---------------------------------------- */ /* ~ Get all fragments ~ */ /* ~ set up GET route ~*/ $app->get('/fragments', function() use($app, $db, $pdo){ // echo $fragments = array(); foreach ($db->fragments() as $fragment) { $fragments[] = array( 'id' => $fragment['id'], 'text' => $fragment['text'] ); } $app->response()->header("Content-Type", "application/json"); echo json_encode($fragments, JSON_FORCE_OBJECT); }); /* ~ Get a single fragment ~ */ $app->get('/fragments/:id', function($id) use ($app, $db, $pdo) { $app->response()->header("Content-Type", "application/json"); $fragment = $db->fragments()->where('id', $id); if($data = $fragment->fetch()){ echo json_encode(array(