A library for mummy that allows you to bind a proc to the router, and automatically parse parameters into the proc arguments.
import mummy, mummy/routers, rowdy
proc getPost(id: int): string =
"you requested a post with id " & $id
var router: Router
router.get(getPost)
router.get("/") do (request: Request):
request.respond(200, body = "the index")
let server = newServer(router)
echo "Serving on http://localhost:8080"
server.serve(Port(8080))
At this point, if you visit http://localhost:8080/getPost?id=4 you should see
you requested a post with id 4
import rowdy
func params(req: Request): QueryParams {.raises: [ValueError].}
proc fromRequest(req: Request; k: string; v: var SomeInteger)
proc fromRequest(req: Request; k: string; v: var SomeFloat)
proc fromRequest(req: Request; k: string; v: var string) {.raises: [ValueError], tags: [].}
proc fromRequest(req: Request; k: string; v: var bool) {.raises: [ValueError], tags: [].}
proc fromRequest[T: object](req: Request; key: string; v: var T)
proc fromRequest[T: ref object](req: Request; key: string; v: var T)
proc fromRequest(req: Request; key: string; v: var Request)
template map(router: var Router; methud: string; handler: proc)
template map(router: var Router; methud, path: string; handler: proc)
template get(router: var Router; handler: proc)
template put(router: var Router; handler: proc)
template delete(router: var Router; handler: proc)
template post(router: var Router; handler: proc)