Skip to content

Instantly share code, notes, and snippets.

@yannick
Created February 15, 2015 18:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yannick/8ab93ad5b84e7561404a to your computer and use it in GitHub Desktop.
Save yannick/8ab93ad5b84e7561404a to your computer and use it in GitHub Desktop.
vibed.d requestHTTP
struct ApiResponse{ int code; string bdy;};
static string UA = "xxx";
ApiResponse get_article(string url_part1, string url_part2) {
ApiResponse ret;
auto url = "http://" ~ url_part1 ~ "/blabla/" ~ url_part2;
requestHTTP(url,
(scope r) {
r.method = HTTPMethod.GET;
r.headers["User-Agent"] = UA;
},
(scope res) {
ret = ApiResponse(res.statusCode, res.bodyReader.readAllUTF8() );
}
);
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment