in reply to How do I make a multipart/mixed request (for REST API) in Perl?

EDIT: I'm an idiot and as the other reply here shows, HTTP::Message already has this functionality built-in. ->add_part() is your friend. I should have looked a bit harder.

OK, so what you're looking for I haven't yet found on the CPAN. This is _completely_ untested, so please take it with a grain of salt (or 100 such grains).

You can create multiple HTTP::Request objects (get, post, etc). You can then group them all together in one new HTTP::Request object with a fairly simple function like I'm showing below and then just send that request:

use UUID qw(uuid); use HTTP::Request (); use Encode (); sub build_multi { my ($method, $uri, $header, @requests) = @_; my $r = HTTP::Request->new($method, $uri, $header); my $boundary = uuid(); $r->header( 'Content-Type' => "multipart/mixed; boundary=$boundary" ); my $content = ''; for my $req (@requests) { $content .= $r->as_string("\015\012"); $content .= "\015\012--{$boundary}"; } $content .= '--' if $content; $r->content( Encode::encode_utf8($content) ); return $r }

AGAIN: completely untested

  • Comment on Re: How do I make a multipart/mixed request (for REST API) in Perl?
  • Download Code

Replies are listed 'Best First'.
Re^2: How do I make a multipart/mixed request (for REST API) in Perl?
by Your Mother (Archbishop) on Nov 28, 2017 at 16:40 UTC

    You're not an idiot at all. The information was buried in one of the sub-sub packages that drive this stuff. I mostly do web work and I didn't know it off the top of my head. I had to track it down and I found a couple nearly identical unanswered questions before realizing the answer wasn't in, or reflected up to, the most intuitive places.

Re^2: How do I make a multipart/mixed request (for REST API) in Perl?
by Anonymous Monk on Nov 28, 2017 at 16:28 UTC
    Yup ... no matter what it is, it is always "built-in" somewhere in CPAN!

      This is simply untrue; an increasingly sad situation that takes enthusiastic devs and the support of the community—in other words, don’t push using an existing tool in another language if someone is interested in building it in Perl—to ameliorate. There are fields where the CPAN has not kept pace. Raw/plain HTTP-oriented stuff, however, is not one of them because this part of the technology hasn't changed much in a couple of decades.