June 2017
Intermediate to advanced
536 pages
9h 49m
English
Given that REST services rely on HTTP, it's safe to assume that writing clients with PHP CURL should be quite a straightforward process. Let's create a rest-service/client/index.php file with the following content:
<?php$ch = curl_init();$headers = [ 'Content-Type: application/json', 'X-AUTH-TOKEN: some-auth-token-here'];curl_setopt($ch, CURLOPT_URL, 'http://rest-service.server/user/welcome');curl_setopt($ch, CURLOPT_POST, true);curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode(['name' => 'John']));curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$result = curl_exec($ch);curl_close($ch);echo $result;
The Wireshark network tool tells us that this code generates the following HTTP ...
Read now
Unlock full access