The API I'm requesting is expecting a GET HTTP method
I want to avoid something like
domain.com/api/v1/module/user?access_token=er78e9wr7fasf7s9a8fsd7fa8f7sa8f for example.
I'd rather be able to request
domain.com/api/v1/module/user
and set the access_token value in the header, I'm aware you can do this with post, but I'd like to do this for a GET method.
I currently have the following
public function fetch()
{
$response = json_decode(
$this->prepareRequest(
new \Web\Curl\Wrapper,
$this->prepareRequestURL()
)->execute()
);
}
private function prepareRequestURL()
{
return $this->apiConfig->getBaseDomain() . $this->apiConfig->getUserSelfURL();
}
private function prepareRequest(\Web\Curl\Wrapper $curlWrapper, $url)
{
$curlWrapper->init($url);
$curlWrapper->setOption(CURLOPT_RETURNTRANSFER, 1);
$curlWrapper->setOption(CURLOPT_HTTPHEADER, array(
$this->apiConfig->getAccessTokenKey() => $_SESSION[$this->apiConfig->getAccessTokenKey()]
));
return $curlWrapper;
}
My curl wrapper class
private $curl;
public function init($requestLocation = null)
{
$this->curl = curl_init($requestLocation);
}
public function preparePost($postData)
{
$this->setOption(CURLOPT_POST, 4);
$this->setOption(CURLOPT_POSTFIELDS, $postData);
$this->setOption(CURLOPT_SSL_VERIFYPEER, false);
$this->setOption(CURLOPT_RETURNTRANSFER, true);
}
public function execute()
{
return curl_exec($this->curl);
}
public function setOption($option, $value)
{
curl_setopt($this->curl, $option, $value);
}