Skip to content

How to extract the route into the method? #37

Answered by sunli829
Oodachi asked this question in Q&A
Discussion options

You must be logged in to vote

Should return impl Endpoint, because with wraps the original Route type into another type.

pub fn app(db: DbConn) -> impl Endpoint {
    route()
        .at("/hello/:name", get(hello))
        .with(RateLimitLayer::new(5, Duration::from_secs(30)).compat())
        .with(TimeoutLayer::new(Duration::from_secs(30)).compat())
        .data(db) // similar to   .with(AddData::new(db))
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Oodachi
Comment options

Answer selected by Oodachi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants