toql_rocket 0.3.0

Rocket integration for Toql
docs.rs failed to build toql_rocket-0.3.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: toql_rocket-0.1.5

Toql Rocket

Use Toql with Rocket.

This crate adds:

  • Toql URL query parameters
  • Response headers with page count information
  • Responder for ToqlError

Add this to your Cargo.toml:

[dependencies]
toql_rocket = "0.3"

Then enjoy some simplifications in your rocket handlers:

use toql_rocket::prelude::{ToqlQUery, Counted};
#[get("/?<toql_query..>")]
pub async fn query(
    cache: &State<Cache>,
    mut conn: Connection<TodoDb>,
    toql_query: ToqlQuery,  //<!-- Get URL parameters with default values
) -> Result<Counted<Json<Vec<Todo>, MyError>>>  
{
    let mut toql = MySqlAsync::from(&mut *conn, &*cache);
    let (query, page) = toql_query.parse::<Todo>()?; //<!-- Parse into typesafe query
    let r = toql.load_page(query, page).await?;

    Ok(Counted(Json(r.0), r.1)) //<!-- Put page count information into headers
}

Check out the full featured REST server based on Rocket, Toql and MySQL.

License

Toql Rocket is distributed under the terms of both the MIT license and the Apache License (Version 2.0).