I am trying to convert a curl request written in ruby to rust. The curl request sends the output to a slack channel:
curl -XPOST #{slack} -d 'payload=#{body}'
, where "slack" is the webhook url to the slack channel.
I was wondering how I can do this in rust. Any help would be greatly appreciated.
Add the reqwest crate to your Cargo.toml
file, with the optional "blocking" feature enabled. (This lets you use a slightly simpler API that does not require an async runtime.)
[dependencies]
reqwest = { version = "0.11", features = ["blocking"] }
Then use reqwest
to send a POST request:
use reqwest::blocking::Client;
let response = Client::post(slack)
.body(format!("payload={}", body))
.send()
.unwrap();
This will return a Response
value, which has various methods for checking the status and content of the response.
1 Like
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.