croservices / cro-http

HTTP (including HTTPS and HTTP/2) support for the Cro library for building distributed systems in Raku.
https://cro.services/
Artistic License 2.0
49 stars 26 forks source link

Add support for setting query parameters in GET requests #90

Closed 0racle closed 4 years ago

0racle commented 4 years ago

Currently there is no support for accepting a Hash or List of Pairs and converting them to query parameters in the GET request.

Example

$client.get('http://localhost/endpoint', form => {foo => 1, bar => 'simple text param'});
# Sends a request to `http://localhost/endpoint?foo=1&bar=simple+text+param`

Keyword may not be form It could be param, or query or something else.

CurtTilmes commented 4 years ago

You can do this with URI::Template:

use URI::Template;
my $template = URI::Template.new(template => 'http://localhost/endpoint{?foo,bar}');
$client.get($template.process(foo => 1, bar => 'simple text param'));

URI::Template supports the variable expansion/templating described in RFC 6570.

I'd love to see that functionality more seamlessly accessible directly from Cro.

jnthn commented 4 years ago

Implemented in https://github.com/croservices/cro-http/commit/12bdacdee8, documentation in https://github.com/croservices/cro/commit/76a755dba2.