コード例 #1
0
 error_reporting(E_ALL);
 //Require the http handler class
 require_once "class/HttpHandler.class.php";
 //Require the utility class
 require_once "class/Utility.class.php";
 //Require the service request class
 require_once "class/ServiceRequest.class.php";
 //Options for service request
 $options = array("authorization_prefix" => "Authorization", "host" => "http://*****:*****@email.com", "password" => "123456"], null, false);
 Utility::debug($auth);
 //Set the token for authenticated methods
 $userToken = $auth->payload->data->token;
 //Example of get request to an unauthenticated route to list user
 echo "<h2 style='color:green;'>[GET] Service route: /user/list_user [TOKEN: {$userToken}]</h2>";
 $listUser = $serviceRequest->get("/user/list_user", null, null, false);
 Utility::debug($listUser);
 //Example of get request to an unauthenticated route to read single user
 echo "<h2 style='color:green;'>[GET] Service route: /user/read_user [TOKEN: {$userToken}]</h2>";
 $readUser = $serviceRequest->get("/user/read_user", ["id" => 1], null, false);
 Utility::debug($readUser);
 //Example of post request to an authenticated route to create an user
 echo "<h2 style='color:green;'>[POST] Service: /user/create [TOKEN: {$userToken}]</h2>";
 $create = $serviceRequest->post("/user/create", ["name" => "Darth Vader", "email" => "*****@*****.**", "password" => "123456"], $userToken, false);
 Utility::debug($create);