Skip to content

Instantly share code, notes, and snippets.

@leonbreedt
Created April 25, 2019 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leonbreedt/a96c9d29f9755624a338eebde590b0bb to your computer and use it in GitHub Desktop.
Save leonbreedt/a96c9d29f9755624a338eebde590b0bb to your computer and use it in GitHub Desktop.
api.rs - extracted function
pub fn customers(pool: &'static db::ConnectionPool) -> impl warp::Filter {
// Clone pool in filter chain so child threads can access it safely.
let database = warp::any().map(move || pool.clone());
let customers = warp::path("customers");
let customers_index = customers.and(warp::path::end());
let customer_by_id = customers
.and(warp::path::param::<i64>())
.and(warp::path::end());
let customer_list = warp::get2()
.and(customers_index)
.and(database.clone())
.and_then(list_customers);
let customer_read = warp::get2()
.and(customer_by_id)
.and(database.clone())
.and_then(read_customer);
let api = customer_list.or(customer_read).recover(handle_errors);
let routes = api.with(warp::log("repo"));
routes
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment