1 | initial version |
Here's an updated PHP script that will act as a proxy, accepting query parameters from the client, making an API call with those parameters, and returning the same result:
<?php
function buildUrl($base, $params) {
$queryString = http_build_query($params);
return $base . '?' . $queryString;
}
function fetchUrl($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$content = curl_exec($ch);
$contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
curl_close($ch);
return [$content, $contentType];
}
$baseUrl = 'THE_API_END_POINT';
$params = $_GET;
$url = buildUrl($baseUrl, $params);
list($content, $contentType) = fetchUrl($url);
header("Content-Type: $contentType");
echo $content;
Replace THE_API_END_POINT
by the API end point you want to wrap.