Rust Crate - surf
Notes on surf
Snippets
-
Basic post requestUsing
surf-2.3.2
,tokio-1.33.0
,serde-1.0.189
.
use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize)]
struct Ip {
message: String,
datetime: String,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let uri = "http://localhost:4000/api/notification";
let data = &Ip {
message: "test".into(),
datetime: "2023-10-14T16:55:15".into(),
};
let _ = surf::post(uri).body_json(data)?.await?;
Ok(())
}