-
Notifications
You must be signed in to change notification settings - Fork 5
Http Client
Brian Zou edited this page Mar 14, 2019
·
2 revisions
auto client = new hunt.http.client.Client();
auto res = client->request('GET', 'https://api.github.com/user', [
'auth' => ['user', 'pass']
]);
writeln(res->getStatusCode());
// "200"
writeln(res->getHeader('content-type')[0]);
// 'application/json; charset=utf8'
writeln(res->getBody());
// {"type":"User"...'
// Send an asynchronous request.
auto request = new hunt.http.client.Request('GET', 'http://httpbin.org');
auto promise = client->sendAsync(request)->then(function (response) {
writeln('I completed! ' ~ response->getBody());
});
promise->wait();