The get(), post(), etc. methods are both too magic, and not magic enough.
They do what I mean, but only if I remember the order or parameters. Luckily Perl has an easy solution to this problem: Named parameters! AKA Passing a hash, like a normal person.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Existing Mojo::UserAgent interface: | |
->get('www.☃.net?hello=there' => {Accept => '*/*'}); | |
->post('https://example.com' => json => {top => 'secret'}); | |
# Alternative improved interface (proposed): | |
->get({ | |
url => 'www.☃.net?hello=there', | |
headers => { Accept => '*/*' }, | |
}); | |
->post({ | |
url => 'https://example.com', | |
json => { top => 'secret' }, | |
}); |