AlexCouch / pluvo

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

Combine the group api with the router api #5

Closed AlexCouch closed 8 months ago

AlexCouch commented 8 months ago

Description

Right now, it's possible to create and add multiple routers, however, this almost mimics the behavior of groups. The whole point of groups is to have common properties between related endpoints and routes. We should simplify this so that creating a new router is the same as creating a new group.

Example

let base = router.new()
|> router.get("/", index.handler)
|> router.get("/login", login.handler)
|> router.get("/register", register.handler)

let jwt_mw = JWTConfig(secret_key: "secret", on_error_handler: on_error)
|> jwt.with_config

let user = router.with_prefix("user")
|> router.get("/post/:post_id", post.view)
|> router.post("/post", post.handler)
|> router.post("/logout", logout.handler)
|> router.enable(jwt_mw)

pluv
|> add_router(base)
|> add_router(user)