WP_CLI
WpOrgApi::json_get_request
Execute a remote GET request.
Method of the class: WpOrgApi{}
No Hooks.
Returns
Mixed|false. False on failure. Decoded JSON on success.
Usage
// private - for code of main (parent) class only $result = $this->json_get_request( $url, $headers, $options );
- $url(string) (required)
- URL to execute the GET request on.
- $headers(array)
- Associative array of headers.
Default: [] - $options(array)
- Associative array of options.
Default: []
WpOrgApi::json_get_request() WpOrgApi::json get request code WP-CLI 2.13.0-alpha
private function json_get_request( $url, $headers = [], $options = [] ) {
$headers = array_merge(
[
'Accept' => 'application/json',
],
$headers
);
$response = $this->get_request( $url, $headers, $options );
if ( false === $response ) {
return $response;
}
$data = json_decode( $response, true );
if ( JSON_ERROR_NONE !== json_last_error() ) {
throw new RuntimeException( 'Failed to decode JSON: ' . json_last_error_msg() );
}
return $data;
}