Skip to main content
added 941 characters in body
Source Link

I have made acreated this simple WordPress REST API where user calls this URLusers can perform:

  Option A
• Types in the following URL in browser:
      → www.example.com/wp-json/v1/getBook/123456?AuthorSurname=Buckley
 
     The responseAPI will retrieve the relevant information and return a response in the browser:
      → {"Book":"Thank you for smoking"} in browser.

  Option B
I• 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 hideprevent the response / replace it with another pagefrom showing whenever user keys in this URLperform Option A.
  The response can only be shown when it is triggered by CURL postvia Option B.

How can I achieve this?

I have made a simple REST API where user calls this URL:

www.example.com/wp-json/v1/getBook/123456?AuthorSurname=Buckley
 
 The response will return: {"Book":"Thank you for smoking"} in browser.

I would like to hide the response / replace it with another page whenever user keys in this URL.
The response can only be shown when it is triggered by CURL post.

How can I achieve this?

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?

added 3 characters in body
Source Link
bueltge
  • 17.1k
  • 7
  • 61
  • 97

I have made a simple REST API where user callcalls this URL:

www.example.com/wp-json/v1/getBook/123456?AuthorSurname=Buckleywww.example.com/wp-json/v1/getBook/123456?AuthorSurname=Buckley

The response will returnedreturn: {"Book":"Thank you for smoking"}{"Book":"Thank you for smoking"} in browser.

I would like to hide the response / replace it with another page whenever user keys in this URL.
The response can only be shown when it is triggered by CURL post.

How can I acheiveachieve this?

I have made a simple REST API where user call this URL:

www.example.com/wp-json/v1/getBook/123456?AuthorSurname=Buckley

The response will returned: {"Book":"Thank you for smoking"} in browser.

I would like to hide the response / replace it with another page whenever user keys in this URL.
The response can only be shown when it is triggered by CURL post.

How can I acheive this?

I have made a simple REST API where user calls this URL:

www.example.com/wp-json/v1/getBook/123456?AuthorSurname=Buckley

The response will return: {"Book":"Thank you for smoking"} in browser.

I would like to hide the response / replace it with another page whenever user keys in this URL.
The response can only be shown when it is triggered by CURL post.

How can I achieve this?

Source Link

Hide response returned from WordPress REST API call

I have made a simple REST API where user call this URL:

www.example.com/wp-json/v1/getBook/123456?AuthorSurname=Buckley

The response will returned: {"Book":"Thank you for smoking"} in browser.

I would like to hide the response / replace it with another page whenever user keys in this URL.
The response can only be shown when it is triggered by CURL post.

How can I acheive this?