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.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-05-05 10:59:50 +0000
Seen: 18 times
Last updated: May 05 '23
How can one obtain live data from interactive broker through API?
Why am I not getting a response when making a URL call in ASP.NET Web API?
Is it possible to have multiple docks in a single project using rswag rails?
How can I retrieve folders using the Vimeo API?
How can the integration between Ready API tool and Zephyr squad be accomplished?
Does Amazon SP API have a designated endpoint to obtain a seller's identification?
What is the process to restrict Google API key using HTTP referrers?