Skip to content

Instantly share code, notes, and snippets.

@mr-pascal
Last active June 9, 2022 17:56
Show Gist options
  • Save mr-pascal/59dd141c061f2da9de77eb50cba3d999 to your computer and use it in GitHub Desktop.
Save mr-pascal/59dd141c061f2da9de77eb50cba3d999 to your computer and use it in GitHub Desktop.
// 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