New crate: asserhttp

50 points trambel

Hey fellow rustaceans,

I wanted to share with you a crate I've been working on lately: asserhttp. It serves the sole purpose of bringing fluent assertions to your http tests.

It is a simple trait providing many asserters. This trait is then implemented for many http clients: reqwest, surf, isahc, hyper and actix.

It enables you to write your tests like this:

use reqwest;
use asserhttp::*;

#[tokio::test]
async fn my_test() {
    reqwest::get("http://localhost/users").await
        .expect_status_ok()
        .expect_content_type_json()
        .expect_body_json_eq(json!({"name": "john.doe"}));
}

It has the benefits of:

  • having a consistent API between all those http clients
  • being fluent !
    • chain your assertions
    • no more local variable (let response = ...) and so no more headache picking the right variable name
    • no need to worry about mutability (most http clients require &mut self for reading response body
  • works for both async and blocking (some clients support only one, some both)
  • works for Result<Response>: no need to .unwrap()
  • provides enough asserters to get the job done

Alright, enough said ! Give it a try and let me know what you do think about it 😃