Closed AlexCouch closed 10 months ago
The final code for get_route
is almost the same as above, the only difference is I've added an extra function to get the params into the header.
pub fn get_route(router: Router, path: String) -> Option(Route){
let path = path
|> path.from_string
path
|> get_lcp(router.tree)
|> option.map(fn(path){
dict.get(router.routes, path)
|> option.from_result
})
|> option.flatten
|> add_params(path)
}
As per #1, the router is given a context object, which is then updated with the request parameters, but this is a bit silly. We have a RouteMethod for a reason.
So that we can have it look more like this, like it was before
The only difference is that we move the storage of the request parameters to the route's RouteMethod instance, which actually simplifies the code a lot.