Title: How to create a HTTP API
Last modified: February 8, 2018

---

# How to create a HTTP API

 *  [weizenhuhn](https://wordpress.org/support/users/weizenhuhn/)
 * (@weizenhuhn)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/how-to-create-a-http-api/)
 * Hello!
 * In [this ](https://wordpress.stackexchange.com/questions/293427/curl-how-to-secure-send-and-fetch-data-in-wordpress)
   post I found out, that it’s possible to send data to another server/domain with
   WP HTTP API.
 * I know already, how to build a post request. So **on click a button at server1**
   it should send the userdata to server2:
 *     ```
       //POST-REQUEST at server1/domain1
         $body = array(
             'username' => 'Bob',
             'email' => 'some@email.com'
         );
   
         $args = array(
             'body' => $body,
             'method' => 'POST',
             'timeout' => '45',
             'redirection' => '5',
             'httpversion' => '1.0',
             'blocking' => true,
             'headers' => array(),
             'cookies' => array()
         );
   
           $response = wp_remote_post( $url, $args );
   
           if ( is_wp_error( $response ) ) {
               $error_message = $response->get_error_message();
               echo "Something went wrong: $error_message";
           } else {
               echo 'Response:<pre>';
               print_r( $response );
               echo '</pre>';
           }
       ```
   
 * What I’ve to do now at server2?
 *     ```
       function getData(){
        if($_POST['username'])
           echo "TEST: " . $_POST['name'];
        //DOESN'T WORK 
       }
       ```
   
 * But how can I fetch this data ($body) at server2/domain2? How to listen at server2,
   if server1 is sending me data?
    I want to grap at server2 the data which I sent
   on server1 on save it in the DB. Could someone show me a little example?
 * I’m sorry if this is pretty simple, but I’m quite new in APIs.
    -  This topic was modified 8 years, 4 months ago by [weizenhuhn](https://wordpress.org/support/users/weizenhuhn/).
    -  This topic was modified 8 years, 4 months ago by [weizenhuhn](https://wordpress.org/support/users/weizenhuhn/).

Viewing 1 replies (of 1 total)

 *  [Soumanta Bhowmick](https://wordpress.org/support/users/soumanta/)
 * (@soumanta)
 * [8 years, 4 months ago](https://wordpress.org/support/topic/how-to-create-a-http-api/#post-9955365)
 * In short, you need to create **Custom endpoints** on server2. ( Assuming your
   server2 has also installed WordPress ).
 * Here is a wordpress.org tutorial on how to add custom endpoints.
    [https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/](https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/)

Viewing 1 replies (of 1 total)

The topic ‘How to create a HTTP API’ is closed to new replies.

## Tags

 * [api](https://wordpress.org/support/topic-tag/api/)
 * [curl](https://wordpress.org/support/topic-tag/curl/)
 * [HTTP](https://wordpress.org/support/topic-tag/http/)

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 1 reply
 * 2 participants
 * Last reply from: [Soumanta Bhowmick](https://wordpress.org/support/users/soumanta/)
 * Last activity: [8 years, 4 months ago](https://wordpress.org/support/topic/how-to-create-a-http-api/#post-9955365)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
