Created
January 31, 2017 19:46
-
-
Save ericjgruber/30fd2a23d6baa7ddbe3218983a95472b to your computer and use it in GitHub Desktop.
RESTful PHP example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Inspirational sources: | |
# http://netflixroulette.net/api/ | |
# http://www.ivangabriele.com/php-how-to-use-4-methods-delete-get-post-put-in-a-restful-api-client-using-curl/ | |
# https://github.com/toddmotto/public-apis | |
function netflix_getter() { | |
$request = 'http://netflixroulette.net/api/api.php'; | |
json_decode($request); | |
$method_name = 'GET'; | |
$request_params = 'Tom Cruise'; | |
if ($request === FALSE) { | |
exit; | |
} | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
if ($method_name == 'GET') { | |
$request .= '?actor=' . $request_params; | |
} | |
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json')); | |
curl_setopt($ch, CURLOPT_URL, $request); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
$response = curl_exec($ch); | |
$response_info = curl_getinfo($ch); | |
curl_close($ch); | |
print json_encode($response); | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment