First download the code from the above link.You will need a server and phpmyadmin to run the code, alternatively you can also run the program on a local server using xampp or wamp.

For creating an API of your own, all you have to do is change the following files as required,rest other stuff has been pre-configured by me so no need to worry about it for basic implementation.You can download code from here.

“api/includes/db_config.php” : Add database connection connection.

“api/routes/site.php” : Here you should define the url for the API and add processing code and output your required json response. Refer Create login api section below for an example.

$req = $app->request() :- Request for data which is coming from font-end.

$requiredfields = array( ‘email‘ , ‘password‘) :- Array for holding list of mandatory fields which will later be validated.

RequiredFields($req->get(), $requiredfields) function takes in two parameters the data and an array of mandatory fields, this function will validate if the required fields are present in the request.Check functions.php for the code.

No only in else condition will set the error.
Actually in if condition i have to name it as a message instead of error .
in both if and else condition message data will come from api (i.e: For Error :- “Email-id or Password doesn’t exist” & For Message :- “User logged in successfully”).
Like,
var message;
if(data.error == 0){
message += “”+data.message+””;
$(“.error-div ul”).html(message);
}else{
error += “”+data.message+””;
$(“.error-div ul”).html(error);
}