I am writing a rest api in slim to be used by an app i am also developing. While debugging I noticed that in screens that I do 3-4 Rest calls (3 gets) my calls wait for the previous call to complete before they proceed. I am trying to figure out if this is a problem with my Slim app or my mobile app.
So calling the following endpoints:
domain/rank
domain/leaderboard
domain/activity
domain/user/{id}
They seem to be procedural and not responding as soon as the data is available.
Any help?
ps. I am also attaching an example of an endpoint to make sure that I am not doing something stupid there
/**
* Get all Activity Posts
*/
$app->get("/activity", function ($request, $response, $arguments) {
try
{
$stmt = $this->get('pdo')->prepare("SELECT posts.*, users.fname, users.lname, users.privacy,
users.photo_url as user_avatar
FROM posts left join users
ON posts.userid = users.id ORDER BY posts.created DESC");
$stmt->execute();
$count = $stmt->rowCount();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
if($count==0)
{
$status = 404;
$responseObject = array();
$responseObject["status"] = $status;
$responseObject["error"] = false;
$responseObject["message"] = "Not found";
}
else
{
$status = 200;
$responseObject = array();
$responseObject["status"] = $status;
$responseObject["error"] = false;
$responseObject["data"] = $result;
}
}
catch(\PDOException $e)
{
$status = 422;
$responseObject = array();
$responseObject["status"] = $status;
$responseObject["error"] = true;
$responseObject["message"] = "Server error";
$responseObject["debug"] = $e->getMessage();
}
return $response->withStatus($status)
->withHeader('Content-Type', 'application/json')
->withJSON($responseObject);
});