HTTP::...Parser(3pm)

πŸ“¦
version 0.200 Β· 5 versions
, in debian bookworm, ubuntu jammy, ubuntu noble

okay so this is a User Contributed Perl Documentation page, it lives in section 3pm of your man pages, and it's literally about one of the most underrated little modules ever: HTTP::Link::Parser. she parses HTTP Link headers. that's the whole gig. and she ate. πŸŽ€


✨ NAME ✨

HTTP::Link::Parser β€” parse HTTP Link headers πŸ¦‹


🌸 SYNOPSIS 🌸

  use HTTP::Link::Parser ':standard';
  use LWP::UserAgent;

  my $ua = LWP::UserAgent->new;
  my $response = $ua->get("http://example.com/foo");

  # Parse link headers into an RDF::Trine::Model.
  my $model = parse_links_into_model($response);

  # Find data about <http://example.com/foo>.
  my $iterator = $model->get_statements(
    RDF::Trine::Node::Resource->new('http://example.com/foo'),
    undef,
    undef);

  while ($statement = $iterator->next)
  {
     # Skip data where the value is not a resource (i.e. link)
     next unless $statement->object->is_resource;

     printf("Link to <%s> with rel=\"%s\".\n",
        $statement->object->uri,
        $statement->predicate->uri);
  }

like. look at that. a whole vibe. πŸ’…


πŸ’œ DESCRIPTION πŸ’œ

so HTTP::Link::Parser parses the HTTP "Link" headers it finds chilling inside an HTTP::Response object. those headers are supposed to follow the format described in RFC 5988 β€” that's the assignment, bestie. πŸ“Ž

🫢 Functions 🫢

if you want every single function exported to you, do this:

  use HTTP::Link::Parser ':all';
  • parse_links_into_model($response, [$existing_model]) β€” she takes an HTTP::Response object (or honestly, any HTTP::Message object, she's not picky) and hands you back an RDF::Trine::Model stuffed with all the link data she dug out of that response. Dublin Core is what's used to encode the 'hreflang', 'title' and 'type' link parameters, just so you know. 🌈 and $existing_model? that's an RDF::Trine::Model you can pass in and she'll add the data to that one. leave it out and she just makes a brand new empty model for you. no biggie. ✨
  • parse_links_to_rdfjson($response) β€” gives you back a hashref whose structure is inspired by the RDF/JSON specification. think of it as the shortcut version of this:
  parse_links_into_model($response)->as_hashref

but faster, because no intermediate model gets built. efficiency queen. πŸ‘‘

  • relationship_uri($short) β€” not exported by default, so don't come for her when it's not just there. πŸ™ˆ she converts short strings that identify relationships β€” think "next" and "prev" β€” into the long URIs identifying those same relationships, like "http://www.iana.org/assignments/relation/next" and "http://www.iana.org/assignments/relation/prev". and if you hand her a string that's already a URI? she just returns it as-is. no notes. πŸ’…

🧚 Internal Functions 🧚

these are lowkey just internal implementations, but like… you can use them if you want. she's not gatekeeping. 🫢

  • parse_links_to_list($response) β€” not exported by default. returns an arrayref of hashrefs. every hashref has keys matching up with the link parameters of the link, plus a key called 'URI' that corresponds to the target of the link. the 'rel' and 'rev' keys are arrayrefs holding lists of relationships β€” and if the Link used the short form of a registered relationship, then the short form is what's sitting on that list. you can turn those short forms into long forms (URIs) with the relationship_uri function. also: the structure this function returns should NOT be considered stable. do not build your whole personality on it. 😭
  • parse_single_link($link, $base, [$default_lang]) β€” not exported by default. this one parses a single Link header (minus the "Link:" bit itself) into a hashref structure. you must include a base URI, in case the link contains relative URIs. and you can optionally provide a default language for the 'title' parameter. same warning as above: the structure returned by this function should not be considered stable. fr fr. πŸ’€

πŸ’€ BUGS πŸ’€

please report any bugs to <http://rt.cpan.org/>. be nice about it, she's doing her best. πŸ₯Ί


πŸ”₯ SEE ALSO πŸ”₯


πŸ‘‘ AUTHOR πŸ‘‘

Toby Inkster <tobyink@cpan.org>. icon behaviour. ⭐


Copyright (C) 2009-2011, 2014 by Toby Inkster

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


okay that's the whole page bestie, go parse some headers, you got this πŸ’–

and that's a wrap! this lil beauty came to you via perl v5.32.0, dated 2021-01-06, and honestly? she's timeless. slay, hydrate, and always read your Link headers βœ¨πŸŒΈπŸ¦‹

πŸ“¦ where this page comes from