Made this clearer, see #175
This commit is contained in:
parent
27984bef3f
commit
54f4acb222
1 changed files with 37 additions and 0 deletions
37
examples/client_auth.php
Normal file
37
examples/client_auth.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
require "../lib/php_crud_api_transform.php";
|
||||
|
||||
function call($method, $url, $data = false) {
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
if ($data) {
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||||
$headers = array();
|
||||
$headers[] = 'Content-Type: application/json';
|
||||
$headers[] = 'Content-Length: ' . strlen($data);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
|
||||
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookies.txt');
|
||||
curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/cookies.txt');
|
||||
|
||||
return curl_exec($ch);
|
||||
}
|
||||
|
||||
// in case you are using php-api-auth:
|
||||
$csrf = call('POST','http://localhost/blog.php/', 'username=admin&password=admin');
|
||||
$response = call('GET','http://localhost/blog.php/posts?include=categories,tags,comments&filter=id,eq,1&csrf='. trim($csrf));
|
||||
$jsonObject = json_decode($response,true);
|
||||
|
||||
$jsonObject = php_crud_api_transform($jsonObject);
|
||||
$output = json_encode($jsonObject,JSON_PRETTY_PRINT);
|
||||
?>
|
||||
<html>
|
||||
<head>
|
||||
</head>
|
||||
<body>
|
||||
<pre><?php echo $output ?></pre>
|
||||
</body>
|
||||
</html>
|
||||
Loading…
Add table
Add a link
Reference in a new issue