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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
extern crate reqwest;
use std::collections::HashMap;
extern crate serde;






pub mod weather{

pub fn textresponse() -> Result<(), Box<dyn std::error::Error>> {

    
    let resp = reqwest::blocking::get("http://api.weatherapi.com/v1/current.json?key=3f3fc68039bb425d9bf213209200407&q=karachi
    ")?
        .text()?;
    println!("{:#?}", resp);
    Ok(())
}

// struct location{
// name: String,
// region: String,
// country: String,
// lat: u32,
// lon: u32,
// tz_id: String,
// localtime_epoch: u32,
// localtime: String,
// }

// struct current{
//     temp_c: u8,
    
// }
// #[derive(Deserialize)]
// struct data{
//     location:location,
//     current:current,
// }



pub fn jsonresponse() -> Result<(), Box<dyn std::error::Error>> {
    let resp = reqwest::blocking::get("http://api.weatherapi.com/v1/current.json?key=3f3fc68039bb425d9bf213209200407&q=karachi
    ")?
    .json()?;
    
    Ok(())
}

}