I have a simple PHP API. I just used cURL
for the Client and $_POST
to accept the requests at the Server side. Something like ..
Client:
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/api-server");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array('q' => 'world!'));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER , 1);
$response = curl_exec($ch);
curl_close($ch);
echo json_decode($response);
?>
Server:
<?php
echo json_encode("hello, ".$_POST["q"]);
?>
My questions here are:
- Am i even still following the standard API logic anyway?
- How to "PROTECT" this API Server Access?