Help language development. Donate to The Perl Foundation

Curlie cpan:BDUGGAN last updated on 2021-10-06

Curlie -- A simple HTTP client built on top of libcurl


An HTTP Client built on libcurl, that provides an OO interface, logging and error handling.


Create a new object manually:

    use Curlie;
    my \c =;

Any options sent in the constructor will be sent to libcurl's setopt.

    my $username = 'alice';
    my $password = 's3cret';
    my \c =$username, :$password);

or create a new object automatically:

    use Curlie :c;

Send a request, and print the full response headers and body:

    say c.get('').res;
    say c.get('').res;
    say c.get('', query => %( name => 'bob' )).res;
    say c.get('', query => rocket => '🚀').res;


    c.get: '';
    say c.res;
    say c.res.content;

The response object is a `Curlie::Response`, and has the following
methods: `status`, `statusline`, `success`, `content`, `raw-headers`, `headers`,
and `json`.

Non-success responses return soft failures:

    say c.get('').res;
    # Fails with:
    # HTTP/2 500
    # and a stack trace

Which means to see the entire response, use it in a boolean context:

    c.get('') or say c.res;
    # Does not fail, prints:
    # HTTP/2 500
    # [ headers, response...]

If you also want to see the request, start a logger using Log::Async, and call `c.debug` beforehand:

    use Log::Async;

Add `curl` or `ssl` options to see extra libcurl or ssl messages:

    c.debug(:curl, :ssl);

Getting json, posting json, posting forms work like this:

    c.get: '', :json; '', :json(:hello<world>); '', :form(:hello<world>);

The response object also has a `json` method which will decode
the body:

    say c.get('').res.json<url>

Also other headers can be sent in a `headers` argument

    say c.get('', :headers(:X-Hello<world>)).res.json<headers><X-Hello>
    # world

That's it! (so far!)


The last version of Curlie can be found at [](

Specific versions of Curlie can be install using zef, for instance:

    zef install




Probably!  Send me patches!


Brian Duggan (bduggan @