glacier-web 0.5.0

A batteries-included web framework for Rust, inspired by Rails, Phoenix and Laravel.
Documentation
//! Records of a nested resource know their paths: `/orgs/42/projects/7`.

use glacier::prelude::*;
use glacier::testing::TestClient;

#[glacier::model]
pub struct Project {
    name: String,
    org_id: i64,
}

struct Projects;

impl Resource for Projects {
    async fn index(_ctx: Context) -> Result<Response> {
        let project = Project {
            id: 7,
            org_id: 42,
            ..Default::default()
        };
        Ok(Response::text(format!(
            "{} {}",
            Project::collection_path(),
            project.to_path()
        )))
    }
}

#[tokio::test]
async fn nested_records_fill_their_params() {
    let app = App::new().routes(|r| {
        r.scope("/orgs/:org_id", |r| {
            r.resources_only::<Projects>("projects", &[glacier::controller::Action::Index]);
        });
    });
    let client = TestClient::new(app);
    // The collection from the request's `:org_id`, the record from its own.
    let res = client.get("/orgs/9/projects").await;
    assert_eq!(res.body_text(), "/orgs/9/projects /orgs/42/projects/7");
    // Outside a request, a record still knows its org.
    let project = Project {
        id: 3,
        org_id: 5,
        ..Default::default()
    };
    assert_eq!(project.to_path(), "/orgs/5/projects/3");
}