WordPress Plugin Development Series (63/95). Prefer one article? Read the complete WordPress plugin development tutorial.
Short description
`wp_remote_get` is the WP-native way to call APIs without requiring curl extensions directly.
wp_remote_get
$response = wp_remote_get('https://api.example.com/data', [
'timeout' => 15,
'headers' => ['Authorization' => 'Bearer ' . $token],
]);
if (is_wp_error($response)) {
return $response;
}
$data = json_decode(wp_remote_retrieve_body($response), true);