I have created this simple WordPress REST API where users can perform:
Option A
• Types in the following URL in browser:
→
www.example.com/wp-json/v1/getBook/123456?AuthorSurname=Buckley
The API will retrieve the relevant information and return a response in the browser:
→
{"Book":"Thank you for smoking"}
Option B
• Perform a CURL statement in CMD or via scripting:
(for Example)
function getBook($authorID, $authorSurname){
$ch = curl_init();
$url = 'www.example.com/wp-json/v1/getBook/123456?AuthorSurname=Buckley';
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:application/json','Content-Type:application/json' ));
curl_setopt($ch, CURLOPT_URL, $url.$authorID.'?AuthorSurname='.$authorSurname);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//execute the POST request
$result = curl_exec($ch);
return $result;
curl_close($ch);
<br><br>
I would like to prevent the response from showing whenever user perform Option A.
The response can only be shown via Option B.
How can I achieve this?