2

I am using a third-party API. And the API has a pagination to navigate through the data. In the header I get the Link parameter where the next, previous, first and last are located, but when I get the Link param with Guzzle I get a *String*.

....
$responseAPI = $httpClient->get($uri);

$linkHeader = $responseAPI->getHeader("Link");
....

I got:

'http://next.com"; rel="next", http://next.com"; rel="prev"'

Is there a way to access the Link with the 'rel' keyword? Like it's an array? or in some other way?

1 Answer 1

3

You can use GuzzleHttp\Psr7\parse_header($response->getHeader('Link')) see the docs:

$client = new \GuzzleHttp\Client();
    
$response = $client->get('https://httpbin.org/response-headers?Link=http://next.com?3;rel="next",http://next.com?1;rel="prev"');

print_r(GuzzleHttp\Psr7\parse_header($response->getHeader('Link')));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.