1
+ <?php
2
+ require "../lib/php_crud_api_transform.php " ;
3
+
4
+ function call ($ method , $ url , $ data = false ) {
5
+ $ ch = curl_init ();
6
+ curl_setopt ($ ch , CURLOPT_CUSTOMREQUEST , $ method );
7
+ curl_setopt ($ ch , CURLOPT_URL , $ url );
8
+ if ($ data ) {
9
+ curl_setopt ($ ch , CURLOPT_POSTFIELDS , $ data );
10
+ $ headers = array ();
11
+ $ headers [] = 'Content-Type: application/json ' ;
12
+ $ headers [] = 'Content-Length: ' . strlen ($ data );
13
+ curl_setopt ($ ch , CURLOPT_HTTPHEADER , $ headers );
14
+ }
15
+ curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
16
+
17
+ curl_setopt ($ ch , CURLOPT_COOKIEJAR , '/tmp/cookies.txt ' );
18
+ curl_setopt ($ ch , CURLOPT_COOKIEFILE , '/tmp/cookies.txt ' );
19
+
20
+ return curl_exec ($ ch );
21
+ }
22
+
23
+ // in case you are using php-api-auth:
24
+ $ csrf = call ('POST ' ,'http://localhost/blog.php/ ' , 'username=admin&password=admin ' );
25
+ $ response = call ('GET ' ,'http://localhost/blog.php/posts?include=categories,tags,comments&filter=id,eq,1&csrf= ' . trim ($ csrf ));
26
+ $ jsonObject = json_decode ($ response ,true );
27
+
28
+ $ jsonObject = php_crud_api_transform ($ jsonObject );
29
+ $ output = json_encode ($ jsonObject ,JSON_PRETTY_PRINT );
30
+ ?>
31
+ <html>
32
+ <head>
33
+ </head>
34
+ <body>
35
+ <pre><?php echo $ output ?> </pre>
36
+ </body>
37
+ </html>
0 commit comments