-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch.php
More file actions
29 lines (16 loc) · 753 Bytes
/
fetch.php
File metadata and controls
29 lines (16 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
//just testing a really simple restful api, next time a soap.
$apiUrl = "http://localhost/restApi.php?action=test"; //where and how is send
$client = curl_init($apiUrl); //init the curl
//test 2 start
$postData = ["name" => "Michael", "lastName"=> "RodGam"];
curl_setopt($client, CURLOPT_POST, true);
curl_setopt($client, CURLOPT_POSTFIELDS, $postData);
//end test 2
curl_setopt($client, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($client); //exc the curl setopt
curl_close($client); //part of test 2
$result = json_decode($response, true); //convert json to php array
$data = "<p>".$result["message"]."</p>"; //makes and html
echo ($data); //send back to index
?>