Hi all
Real newbie trying to learn Rust ... Started off to write a basic little program that basically just queries and API and then should parse the response. I am having real trouble getting deceriazing the json response into a struct.
Here is the code so far :
extern crate reqwest;
use reqwest::header::{HeaderMap , HeaderValue, AUTHORIZATION};
use serde_derive::{Serialize, Deserialize};
use serde_json;
use serde::Deserialize;
#[derive(Deserialize)]
struct Confidence {
min_confidence : i32,
average_configende : i32,
max_confidence : i32,
}
fn main() {
let ioc = "value to be searched";
let api_key = "api key details";
let base_url= format!("https://domain.com/?type=confidence&value={}", ioc) ; // Join the &str and String to create full URL
let full_url = &base_url[..]; // Convert String to &str which is required by reqwest::blocking::client
let mut request_header = HeaderMap::new();
request_header.insert( AUTHORIZATION, HeaderValue::from_static(api_key));
let client = reqwest::blocking::Client::new();
let mut response_full = client.get(full_url)
.headers(request_header)
.send();
//println!("Printing Body : {:#?}" , response.unwrap().text() ) ; // prints the body
If i un-comment the println this is the output :
Body : Ok(
"{"min_confidence": 0, "average_confidence": 0, "max_confidence": 0}",
)
I think by now i have tried at least 10 different 'ways' of trying to get the data into the stuct using various json methods ( just copying/editing lots of examples i have found on the internet that look familiar ) and had 0 luck .
Any help would be greatly appreciated , i have tried readin the crate documentation pages for reqwest and serde but it's just confused me more