AlexCouch / pluvo

Pluvo is a modern web framework purely in Gleam built ontop of mist
4 stars 0 forks source link

Request parameters #1

Closed AlexCouch closed 8 months ago

AlexCouch commented 8 months ago

Description

A request parameter is a path with a parameter in its path. A route that is registered with a parameter will be able to accept that parameter through the context.

Example

A route handler written like this

pub fn view(ctx: Context) -> Response(ResponseData){
    use user_id <- context.then(ctx |> context.get_param("id"))
    ctx 
    |> context.text("Hello, user " <> user_id)
}

A route registered like this

let routes = pluv |> pluvo.router
|> router.get("/user/:id", user.handler)

Implementation Details

We have everything we need to do this. We have a basic lcp (longest common part) implemented, but there's some issues with it.

  1. It doesn't actually compare the number of equal parts existing between the request path and a registered path
  2. We are searching the routes dict and not the nodes. The nodes are there so we can do stuff like this and traverse all the possible routes and speed up the search
AlexCouch commented 8 months ago

I have updated the example above to match one of the test routes. It currently is a mess so we are gonna have to fix it all up in other issues.