Course of Raku / Functional, concurrent, reactive, and web programming / Web programming / A simple HTTP client / Exercises / Status with a client
Solution: Status with a client
Here is a possible solution to the task.
Code
use Cro::HTTP::Client;
my $response = await Cro::HTTP::Client.get('http://example.com/');
say $response.status;🦋 You can find the source code in the file status-line.raku.
Output
200Comments
Cro::HTTP::Client.getreturns a promise — a network request finishes later — so weawaitit.The response object already knows its
.status, so we get200directly, without sending the request text or parsing the reply by hand. Compare this with the raw-socket version: the module does all the protocol work for you.