api de gestion de ticket, basé sur php-crud-api. Le but est de décorrélé les outils de gestion des données, afin
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

client.php 971B

123456789101112131415161718192021222324252627282930313233343536
  1. <?php
  2. require "../lib/php_crud_api_transform.php";
  3. function call($method, $url, $data = false) {
  4. $ch = curl_init();
  5. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
  6. curl_setopt($ch, CURLOPT_URL, $url);
  7. if ($data) {
  8. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  9. $headers = array();
  10. $headers[] = 'Content-Type: application/json';
  11. $headers[] = 'Content-Length: ' . strlen($data);
  12. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  13. }
  14. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  15. return curl_exec($ch);
  16. }
  17. $response = call('GET', 'http://localhost/api.php/posts?include=categories');
  18. $jsonObject = json_decode($response, true);
  19. $jsonObject = php_crud_api_transform($jsonObject);
  20. $output = json_encode($jsonObject, JSON_PRETTY_PRINT);
  21. $object = array('user_id'=>1,'category_id'=>1,'content'=>'from php');
  22. call('POST', 'http://localhost/api.php/posts',json_encode($object));
  23. ?>
  24. <html>
  25. <head>
  26. </head>
  27. <body>
  28. <pre><?php echo $output ?></pre>
  29. </body>
  30. </html>