Minimalistic HTTP Client Test Utilities.
- Built on top of reqwest.
- Optimized for testing convenience, not for performance.
- Do not use for production/application code, just for testing.
- For production code (apps, services, ...) use the underlying reqwest library and its utilities.
Thanks
- Thanks to @defic for the type client
get/post/put/patch/delete and the response body... apis.
Example
use anyhow::Result;
use serde_json::{json, Value};
#[tokio::test]
async fn test_simple_base() -> httpc_test::Result<()> {
let hc = httpc_test::new_client("http://localhost:8080")?;
let res = hc.do_get("/hello").await?; res.print().await?;
let auth_token = res.res_cookie_value("auth-token"); let content_type = res.header("content_type");
let res = hc.do_get("/context.rs").await?;
res.print_no_body().await?;
let json_value = hc.get::<Value>("/api/tickets").await?;
let res = hc
.do_post(
"/api/tickets",
json!({
"subject": "ticket 01"
}),
)
.await?;
res.print().await?;
let res = hc
.do_post(
"/api/tickets",
(r#"{
"subject": "ticket bb"
}
"#,
"application/json"),
)
.await?;
res.print().await?;
Ok(())
}
This GitHub repo