You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is my(rust beginner) note to remind myself how I got GET method working by postman's generated rust code using tokio. the api server is an internal one. I would be interested to do this doc again if there is public api server that I can do CRUD with.
IMHO, the generated code from https://curlconverter.com/rust/ is more rust beginner friendly. ie without using tokio crate.
// private info masked.
// Get postman GUI configured to be abled query remote https server first.
// Generate code.
// Curl code, --secure added to skip https server certificate check.
// curl --insecure --location 'https://ca01.test.net/nodes?includeAttributes=name%2CoverallHealthState%2Cipv4Addresses&status=managed' \
// --header 'Authorization: Basic YXBpMDE6JDZaNmxxxxxxx'
// Generated by postman after GUI config was configured ok and got the list of nodes
// Cargo.toml has following two lines.
// reqwest = {version = "0.11.18", features = ["blocking", "json"] }
// tokio = { version = "1.29.1", features = ["full"] }
use tokio;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = reqwest::Client::builder()
.danger_accept_invalid_certs(true) // To skip certificate check in a testing environment.
.build()?;
let mut headers = reqwest::header::HeaderMap::new();
headers.insert("Authorization", "Basic YXBpMDE6JDZaNmxxxxxxx".parse()?);
let request = client.request(reqwest::Method::GET, "https://ca01.test.net/nodes?includeAttributes=name,overallHealthState,ipv4Addresses&status=managed")
.headers(headers);
let response = request.send().await?;
let body = response.text().await?;
println!("{}", body);
Ok(())
}
//// Generated from https://curlconverter.com/rust/
//
//extern crate reqwest;
//use reqwest::header;
//
//fn main() -> Result<(), Box<dyn std::error::Error>> {
// let mut headers = header::HeaderMap::new();
// headers.insert("Authorization", "Basic YXBpMDE6JDZaNmxxxxxxx".parse().unwrap());
//
// let client = reqwest::blocking::Client::builder()
// .redirect(reqwest::redirect::Policy::none())
// .danger_accept_invalid_certs(true)
// .build()
// .unwrap();
//
// let res = client.get("https://ca01.test.net/nodes?includeAttributes=name%2CoverallHealthState%2Cipv4Addresses&status=managed")
// .headers(headers)
// .send()?
// .text()?;
// println!("{}", res);
//
// Ok(())
//}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi
This is my(rust beginner) note to remind myself how I got GET method working by postman's generated rust code using tokio. the api server is an internal one. I would be interested to do this doc again if there is public api server that I can do CRUD with.
IMHO, the generated code from https://curlconverter.com/rust/ is more rust beginner friendly. ie without using tokio crate.
Beta Was this translation helpful? Give feedback.
All reactions