Template:REST API GET sample code (php+curl)
From Linux Web Expert
(Redirected from Template:REST API GET sample code (php))
<?php
$url = "https://en.wikipedia.org/w/rest.php/some/path";
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );
echo($output);
?>
<?php
/*
Sample code
*/
$url = "https://test.example/foo";
$params = [ "x" => "1", "y" => "2" ];
$url = $url . "?" . http_build_query( $params );
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_USERAGENT, "MediaWiki REST API docs examples/0.1 (https://www.mediawiki.org/wiki/API_talk:REST_API)" );
$output = curl_exec( $ch );
curl_close( $ch );
echo($output);
?>
Template documentation
[create]