Curl Request from Ruby to Rust

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.)

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))

This will return a Response value, which has various methods for checking the status and content of the response.

1 Like