Consuming REST in Wordpress

Asked

Viewed 1,064 times

0

Good morning!

I implemented a Rest API with Spring and would like to consume it on a site within Wordpress.

This is done through Plugins or direct with code within the Post?

For a Post Request, how would link the data of a form in the http request?

Thank you.

1 answer

1

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

wp_remote_get()

wp_remote_post()

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

example of documentation:

$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
}
  • Good evening! Thank you very much for the answer. Got it. My question is really how to consume this data returned by the Json API. I thought that there was a higher level, however I must use PHP code. I will search how to do this because I have no experience. But how do I Binding the date for inputs or Tables? Abço.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.