<< terug naar ikregeer.nl API documentatie
Hieronder een voorbeeld in PHP, Python en Ruby hoe je de API Key meestuurd:
PHP (met curl)
<?php // Fill your API key in here. $apikey = ""; $url = "http://api.ikregeer.nl/document/KST126651"; $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, $url); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_handle, CURLOPT_POST, 1); curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "apikey=" . $apikey); $buffer = curl_exec($curl_handle); curl_close($curl_handle); var_dump(json_decode($buffer)); ?>
PHP (met Zend Framework)
<?php
// Make sure you have Zend framework in your include path
set_include_path('.' . PATH_SEPARATOR . '../library/Zend' . PATH_SEPARATOR . get_include_path());
require 'Zend/Loader.php';
require 'Zend/Http/Client.php';
require 'Zend/Json/Decoder.php';
// Fill your API key in here.
$apikey = "";
$url = "http://api.ikregeer.nl/document/KST126651";
class App_HttpClient
{
const HTTP_METHOD = 'POST';
protected $client;
protected $apikey;
public function __construct($apikey)
{
$this->client = new Zend_Http_Client();
$this->apikey = $apikey;
}
public function call($url)
{
$this->client->setUri($url);
$this->client->setParameterPost('apikey', $this->apikey);
$result = $this->client->request(self::HTTP_METHOD);
return Zend_Json_Decoder::decode($result->getBody());
}
}
$client = new App_HttpClient($apikey);
$json = $client->call($url);
var_dump($json);
?>
Python
#!/usr/bin/env python
import StringIO
import urllib
import urllib2
# Since version 2.6.0 Python includes an older simplejson as json, we prefer
# to import simplejson, as the 2.x releases are faster.
try:
import simplejson as json
except ImportError:
import json
# Fill your API key in here.
APIKEY = ""
URL = "http://api.ikregeer.nl/document/KST126651"
postfields = urllib.urlencode([('apikey', APIKEY)])
request = urllib2.Request(URL, postfields)
jsondata = StringIO.StringIO(urllib2.urlopen(request).read())
result = json.load(jsondata)
jsondata.close()
print json.dumps(result, indent=4)
Ruby
#!/usr/bin/ruby require 'rubygems' require 'rest_client' # Fill your API key in here. APIKEY = "" url = "http://api.ikregeer.nl/document/KST126651" result = RestClient.post url, "apikey" => APIKEY print result