[−][src]Function rubric::helpers::web::post_json
pub fn post_json<B: Serialize>(url: &str, body: B) -> Result<Response, Error>
Sends a POST request to the url with the given body
body
must be JSON serializable with serde
Example
use rubric::helpers::web::post_json; // We'll use a HashMap because it's similar to json use std::collections::HashMap; let mut data = HashMap::new(); data.insert("key", "value"); // This url just returns whatever we send it let result = post_json("https://postman-echo.com/post", data); // If the result went through if let Ok(resp) = result { // If the result contains a body if let Ok(text) = resp.text() { assert!(text.contains("value")); } }