Skip to content

Instantly share code, notes, and snippets.

@woutersf
Last active January 3, 2017 10:00
Show Gist options
  • Save woutersf/15f3396b45981f3ab7d182b929f9624f to your computer and use it in GitHub Desktop.
Save woutersf/15f3396b45981f3ab7d182b929f9624f to your computer and use it in GitHub Desktop.
Drupal8 version of drupal_http_request
<?php
$client = \Drupal::httpClient();
$url = 'http://something.com/data.json';
try {
$request = $client->get($url);
$status = $request->getStatusCode();
//Do something here.
//For example:
return json_decode($request->getBody()->getContents());
}
catch (RequestException $e) {
//An error happened.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment