in reply to Perl to collect "Link" values contains "next"

>See HTTP::Headers. Don't convert them to a string and then try to parse out the >Link, but access it directly, using the ->header() method:

#!perl use warnings; use strict; use HTTP::Headers; use 5.012; my $headers = HTTP::Headers->new(); $headers->header( 'Cache-Control' => 'no-cache, no-store', 'Connection' => 'close', 'Date' => 'Fri, 26 Mar 2021 02:11:16 GMT', 'Pragma' => 'no-cache', 'Server' => 'nginx', 'Vary' => 'Accept-Encoding', 'Content-Type' => 'application/json', 'Expires' => '0', 'Client-Date' => 'Fri, 26 Mar 2021 02:11:16 GMT', 'Client-Peer' => '10.10.1.32:8080', 'Client-Response-Num' => '1', 'Client-Transfer-Encoding' => 'chunked', 'Expect-Ct' => 'report-uri="https://org.extract.net", max-age=0', 'Link' => '<https://sso.myorg.com/api/v5/myids?limit=200>; rel="se +lf"', 'Link' => '<https://sso.myorg.com/api/v5/myids?after=200xxxxxxxxxx +xxxxxxx&limit=200>; rel="next"', ); say "Found link headers:"; for my $h ( $headers->header('Link') ) { if( $h =~ /\brel="next"/ ) { say "Found 'next' link: $h"; } else { say "Ignoring other Link header: $h"; }; }; __END__ Found link headers: Ignoring other Link header: <https://sso.myorg.com/api/v5/myids?limit= +200>; rel="self" Found 'next' link: <https://sso.myorg.com/api/v5/myids?after=200xxxxxx +xxxxxxxxxxx&limit=200>; rel="next"

Replies are listed 'Best First'.
Re^2: Perl to collect "Link" values contains "next"
by chandantul (Scribe) on Mar 28, 2021 at 01:47 UTC

    Thanks team I was able to resolve my pagination issue below below object in the sub function in my code

    $client->request(HTTP::Request->new('GET', "$_[0]"));

    and resolved the the Link next function

    $linkheader = $response->header('Link'); if ($linkheader=~ m/next/) {......}