Name
SPVM::HTTP::Tiny - A User-Friendly HTTP Client based on Mojo::UserAgent
Description
HTTP::Tiny class in SPVM is a simple HTTP client.
This class is highly experimental. Many dramatic incompatibilities are expected.
Usage
use HTTP::Tiny;
use Go::Context;
my $ctx = Go::Context->background;
my $http = HTTP::Tiny->new;
# GET request
my $response = $http->get($ctx, 'http://example.com/');
unless ($response->success) {
die "Failed to fetch!";
}
# Status and Reason
my $status = $response->status;
my $reason = $response->reason;
# Accessing headers
my $headers = $response->headers;
my $content_type = $headers->header("Content-Type");
# Accessing content
my $content = $response->content;
if (Fn->length($content) > 0) {
print $content;
}
Details
Wrapper of Mojo::UserAgent
This class is a wrapper of Mojo::UserAgent. Unlike Perl's original HTTP::Tiny, this implementation depends on the Mojo stack to support non-blocking I/O and Go coroutines.
Fields
ua
has ua : ro Mojo::UserAgent;
The Mojo::UserAgent object used for HTTP requests.
Class Methods
new
static method new : HTTP::Tiny ($options : object[] = undef);
Creates a new HTTP::Tiny object.
Note: Currently, $options are ignored in the new method. The default User-Agent string is SPVM/HTTP::Tiny/$VERSION and max_redirects is set to 5.
Instance Methods
get
method get : HTTP::Tiny::Response ($ctx : Go::Context, $url : string, $options : object[] = undef);
Sends an HTTP GET request.
head
method head : HTTP::Tiny::Response ($ctx : Go::Context, $url : string, $options : object[] = undef);
Sends an HTTP HEAD request.
put
method put : HTTP::Tiny::Response ($ctx : Go::Context, $url : string, $options : object[] = undef);
Sends an HTTP PUT request.
post
method post : HTTP::Tiny::Response ($ctx : Go::Context, $url : string, $options : object[] = undef);
Sends an HTTP POST request.
patch
method patch : HTTP::Tiny::Response ($ctx : Go::Context, $url : string, $options : object[] = undef);
Sends an HTTP PATCH request.
delete
method delete : HTTP::Tiny::Response ($ctx : Go::Context, $url : string, $options : object[] = undef);
Sends an HTTP DELETE request.
request
method request : HTTP::Tiny::Response ($ctx : Go::Context, $method : string, $url : string, $options : object[] = undef);
Sends an HTTP request with the specified method.
Options (as a Hash):
headers: object[] (Hash-like)Custom headers for the request.
my $res = $http->request($ctx, "GET", $url, {headers => {"X-Custom" => "Value"}});
Repository
Author
Yuki Kimoto kimoto.yuki@gmail.com
Copyright & License
Copyright (c) 2026 Yuki Kimoto
MIT License