Name

SPVM::HTTP::Tiny - HTTP Client

Description

The HTTP::Tiny class of SPVM has methods for a HTTP client.

This class does not work well now. It will be fixed in the near future.

Usage

use HTTP::Tiny;

my $response = HTTP::Tiny->new->get('http://example.com/');

unless ($response->success) {
  die "Failed!";
}

say $response->status;

say $response->reason;

for my $header_name (@{$response->headers->names}) {
  my $header_value = $response->headers->header($header_name);
  
  say $header_value;
}

if (length $response->content) {
  print $response->content;
}

Fields

agent

has agent : ro string;

The user agent.

timeout

has timeout : ro double;

The request timeout seconds.

Class Methods

new

static method new : HTTP::Tiny ($options : object[] = undef);

Creates a new HTTP::Tiny object.

Options:

agent : string

Sets the "agent" field.

timeout : Double

Sets the "timeout" field.

Instance Methods

get

method get : HTTP::Tiny::Message::Response ($url : string, $options : object[] = undef);

Gets the HTTP response by sending an HTTP GET request to the URL $url.

The HTTP response is a HTTP::Tiny::Message::Response object.

Options:

headers : HTTP::Tiny::Headers

Headers for an HTTP request.

timeout : Double

Timeout seconds.

method head : HTTP::Tiny::Message::Response ($url : string, $options : object[] = undef);

put

method put : HTTP::Tiny::Message::Response ($url : string, $options : object[] = undef);

post

method post : HTTP::Tiny::Message::Response ($url : string, $options : object[] = undef);

patch

method patch : HTTP::Tiny::Message::Response ($url : string, $options : object[] = undef);

delete

method delete : HTTP::Tiny::Message::Response ($url : string, $options : object[] = undef);

Repository

SPVM::HTTP::Tiny - Github

Author

Yuki Kimoto kimoto.yuki@gmail.com

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License