Build Status


HTTP::Request::AsCurl - Generate a curl command from an HTTP::Request object.


use HTTP::Request::Common;
use HTTP::Request::AsCurl qw/as_curl/;

my $request = POST('', { 
    target => 'mothership', 
    when   => 'now' 

system as_curl($request);

print as_curl($request, pretty => 1, newline => "\n", shell => 'bourne');
# curl \
# --request POST \
# --dump-header - \
# --data target=mothership \
# --data when=now


This module converts an HTTP::Request object to a curl command. It can be used for debugging REST APIs.

It handles headers and basic authentication.


as_curl($request, %params)

Accepts an HTTP::Request object and converts it to a curl command. If there are no %params, as_curl() returns the cmd as an array suitable for being passed to system().

If there are %params, as_curl() returns a formatted string. The string's format defaults to using "\n" for newlines and escaping the curl command using bourne shell rules unless you are on a win32 system in which case it defaults to using win32 cmd.exe escaping rules.

Available params are as follows

newline: defaults to "\n"
shell:   currently available options are 'bourne' and 'win32'


Copyright (C) Eric Johnson.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


Eric Johnson