Skip to content

Instantly share code, notes, and snippets.

@rippinrobr
Last active May 24, 2018 23:07
Show Gist options
  • Save rippinrobr/12f8d0e4cd1a806f68b8f8f1356d70df to your computer and use it in GitHub Desktop.
Save rippinrobr/12f8d0e4cd1a806f68b8f8f1356d70df to your computer and use it in GitHub Desktop.
The updated resource mapping with the default settings
App::with_state(State{db: addr.clone()})
// the default_resource call here uses a closure
// to return 405 Method Not Allowed error for
// all routes
.default_resource(|r| {
r.route().filter(pred::Not(pred::Get()))
.f(|req| HttpResponse::MethodNotAllowed());
})
.resource("/", |r| r.method(http::Method::GET).f(index))
.resource("/conspiracies/{page_id}", |r| r.method(http::Method::GET).a(get_conspiracies_by_id))
.resource("/tags", |r| r.method(http::Method::GET).a(get_tags))
.resource("/conspiracies", |r| r.method(http::Method::GET).a(get_conspiracies))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment