I made an API through Slim framework and I was testing it using the Advanced Rest Client. Now I want to implement in my php website the API rest. How Can I do that? Is better use AJAX or PHP for that? Can you give a small code demo?
Thanks in advance, I really appreciate.
I tried this code,is this the best solution: My problem here is that I need to add a header with an authorization key.
$data = array("title" => "otro libro", "isbn" => "998-84-8184-1", "author" => "otro autor :)");
$ch = curl_init("http://localhost/slimrest/books");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($data));
$response = curl_exec($ch);
curl_close($ch);
if(!$response)
{
return false;
}
else
{
var_dump($response);
}