1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#![deny(warnings)]
extern crate nightfly;
use lunatic::Mailbox;
// This is using the `lunatic` runtime.
//
#[lunatic::main]
fn main(_: Mailbox<()>) -> () {
// Some simple CLI args requirements...
let url = match std::env::args().nth(1) {
Some(url) => url,
None => {
println!("No CLI URL provided, using default.");
// "https://hyper.rs".into()
// "http://localhost:3000".into()
"http://eu.httpbin.org/get".into()
}
};
eprintln!("Fetching {:?}...", url);
// nightfly::get() is a convenience function.
//
// In most cases, you should create/build a nightfly::Client and reuse
// it for all requests.
let res = nightfly::get(url).unwrap();
eprintln!("Response: {:?} {}", res.version(), res.status());
eprintln!("Headers: {:#?}\n", res.headers());
let body = res.text().unwrap();
println!("{}", body);
// Ok(())
}