Last active
June 9, 2022 17:56
-
-
Save mr-pascal/59dd141c061f2da9de77eb50cba3d999 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a Map of string key-value pairs | |
// to represent the body payload | |
let mut map = HashMap::new(); | |
map.insert("lang", "rust"); | |
map.insert("body", "json"); | |
// - Doing a POST request | |
// - Parse the response to the "JSONResponse" struct | |
let resp_json = client.post("https://httpbin.org/anything") | |
.json(&map) | |
.send() | |
.await? | |
.json::<JSONResponse>() | |
.await?; | |
println!("{:#?}", resp_json); | |
// Output: | |
/* | |
JSONResponse { | |
json: { | |
"body": "json", | |
"lang": "rust", | |
}, | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment