if (empty($me)) { throw new AccessDeniedHttpException("Unknown user({$my_id}), please register first to get your id"); } $app["me"] = $me; }); /******************* API controllers **********************/ $app->post('/api/v1/register/', function (Request $request) use($app) { $name = $request->get('name'); if (empty($name)) { throw new ValidationException("Please provide valid name"); } $personModel = new PersonModel($app['db']); if (!empty($personModel->findByName($name))) { throw new ValidationException("Person with name '{$name}' already exists"); } $data = $personModel->create($name); return $app->json($data); }); // Add user to your friends (send request) $app->post('/api/v1/person/add/', function (Request $request) use($app) { $friend_id = intval($request->get("friend_id")); $personModel = new PersonModel($app['db']); if (empty($personModel->findById($friend_id))) { throw new ValidationException("Unknown friend_id={$friend_id}"); } $personModel->createFriendRequest($app["me"]["id"], $friend_id); return $app->json([], 204); }); // Get the list of pending friendship requests $app->get('/api/v1/person/pending/', function () use($app) { $personModel = new PersonModel($app['db']);