January 2019
Intermediate to advanced
520 pages
14h 32m
English
The next thing we have to add to our App instance is routing. There is a route function that lets you set a handler for any route. But it's more thoughtful to use scopes to construct a structure of nested paths. Look at the following code:
app.scope("/api", |scope| { scope .route("/signup", http::Method::POST, signup) .route("/signin", http::Method::POST, signin) .route("/new_comment", http::Method::POST, new_comment) .route("/comments", http::Method::GET, comments)})
The scope method of our App struct expects a prefix of a path and a closure with a scope as a single argument, and creates a scope that can contain subroutes. We create a scope for the /api path prefix and add four routes using the route method: /signup, /signin ...
Read now
Unlock full access