I’m building a Symfony REST API, with a connection to another API. Because the other API has limited requests per day, I want to cache the results and just call for new results, if the cache is outdated.
After some research I found out, that you could either do a HEAD-Request (which is not support by the API) or send some Request-Headers, like
Speaking of which, I tried to implement the header into my request:
$requestURL = self::BASE_URL . '?trackingNumber=xxxxxxxxxxxxxx'; $response = $this->client->request('GET', $requestURL, [ 'headers' => [ 'ETag' => md5('trackingNumber=xxxxxxxxxxxxxx'), 'If-Modified-Since' => 'Sat, 29 Oct 2022 19:43:31 GMT', 'Api-Key' => $this->api_key, ] ]);
To get to the point: This doesnt work. I still get a 200 Status Code, instead of a Status Code 304, which should clearly be the case with this header.
So, does the API specifically need to accept this header or am I missing something? Do I have an alternative if the API does not support anything in this direction? I mean, it is also in the interest of the provider, to keep the server traffic low.
Source: Ask PHP