HTTP::Request::FromFetch - turn a Javascript fetch() statement into HTTP::Request
my $ua = LWP::UserAgent->new(); my $req = HTTP::Request::FromFetch->new(<<'JS')->as_request; await fetch("https://www.example.com/index.html", { "credentials": "include", "headers": { "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:74.0) Gecko/20100101 Firefox/74.0", "Accept": "text/javascript, text/html, application/xml, text/xml, */*", "Accept-Language": "de,en-US;q=0.7,en;q=0.3", "X-CSRF-Token": "secret", "X-Requested-With": "XMLHttpRequest" }, "referrer": "https://www.example.com/", "method": "GET", "mode": "cors" }); JS $ua->request( $req );
This module parses a call to the Javascript Fetch API and returns an object that you can turn into a HTTP::Request to use with LWP::UserAgent or other user agents to perform a largely identical HTTP request.
The parsing of the Javascript stanza is done through a regular expression, so the test must largely follow the pattern shown in the synopsis. Usually, the fetch() stanzas come from a browsers "Copy as fetch" context menu, so there is no problem parsing these.
fetch()
This is mostly a factory class for HTTP::Request::CurlParameters objects.
Javascript Fetch API
The public repository of this module is http://github.com/Corion/HTTP-Request-FromCurl.
The public support forum of this module is https://perlmonks.org/.
Please report bugs in this module via the RT CPAN bug queue at https://rt.cpan.org/Public/Dist/Display.html?Name=HTTP-Request-FromCurl or via mail to filter-signatures-Bugs@rt.cpan.org.
Max Maischein corion@cpan.org
corion@cpan.org
Copyright 2018 by Max Maischein corion@cpan.org.
This module is released under the same terms as Perl itself.
To install HTTP::Request::FromCurl, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTTP::Request::FromCurl
CPAN shell
perl -MCPAN -e shell install HTTP::Request::FromCurl
For more information on module installation, please visit the detailed CPAN module installation guide.