Skip to content

Instantly share code, notes, and snippets.

@mosampaio
Last active August 24, 2016 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mosampaio/94dbff24b7e561a1960ffc5f9ca965e1 to your computer and use it in GitHub Desktop.
Save mosampaio/94dbff24b7e561a1960ffc5f9ca965e1 to your computer and use it in GitHub Desktop.
How to consume a json Rest API with PHP using PHP Curl
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("user-agent: my app"));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, "https://api.github.com/repos/twilio/twilio-php/contributors");
$result = curl_exec($ch);
curl_close($ch);
print_r(json_decode($result, true));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment