// echo json response echoRespnse(401, $response); } }); /* ---------------- METHODS WITH AUTHENTICATION ------------------ */ /** * Listing all users excluding requested user * method GET * url /list_all_users.php */ $app->get('/list_all_users.php', 'authenticate', function () { global $user_id; $response = array(); $db = new DbHandler(); // fetching all users $result = $db->getAllUsers($user_id); if ($result) { $response["error"] = false; $response["users"] = array(); // looping through result and preparing user array while ($users = $result->fetch_assoc()) { $tmp = array(); $tmp["user_id"] = $users["user_id"]; $tmp["email"] = $users["email"]; $tmp["first_name"] = $users["first_name"]; $tmp["last_name"] = $users["last_name"]; array_push($response["users"], $tmp); } // echo json response echoRespnse(200, $response); } else {
$app->post('/testapikey', 'authenticate', function () { $response = array(); $response["error"] = false; $response["message"] = "Api key is actual"; $response["success"] = 1; echoRespnse(200, $response); }); /** * Listing all users * method GET * url /users/all */ $app->get('/users/all', 'authenticate', function () { $db = new DbHandler(); // listing all users $result = $db->getAllUsers(); $response = array(); if ($result == null) { $response["success"] = 0; $response["error"] = true; } else { $response["success"] = 1; $response["error"] = false; $response["users"] = $result; } echoRespnse(200, $response); }); /** * Get user by id * method GET * url /users/:id