Consuming REST on Wordpress

0

Good morning!

Implemented a Rest API with Spring and would like to consume it on a website within Wordpress.

Is this done through Plugins or Direct with code inside the Post?

For a Post Request, how would you link a form's data in the http request?

Thank you.

    
asked by anonymous 19.05.2017 / 16:21

1 answer

0

If you "implemented a Rest API" I think you just need to know the native WP methods to make requests:

wp_remote_get()

wp_remote_post()

Under the hood they do more or less the same thing, they use the same method to make external requests, and you pass in the arguments the type of request (POST, PUT, UPDATE, etc), headers and other information.

Documentation example:

$response = wp_remote_get( 'http://www.example.com/index.html', $args );

if ( is_array( $response ) && ! is_wp_error( $response ) ) {
    $headers = $response['headers']; // array of http header lines
    $body    = $response['body']; // use the content
}
    
19.05.2017 / 16:32