How can I generate a link to a particular route in Iron?

67 views Asked by At

There's a table with a list of user on an html page. How can I generate a link to a page where I show an information about a single user? "/users/:user_name" ?

I can hard-code it, of course. But I want to be safer by generating with help of Iron.

1

There are 1 answers

0
Shepmaster On

Iron's router has two macros that work together.

router! allows you to define routes with a key:

let router = router!(index: get  "/"       => index,
                     query: get  "/:query" => queryHandler,
                     post:  post "/"       => postHandler);

url_for! allows you to generate a URL for a key:

url_for!(request, "foo",
         "query" => "test",
         "extraparam" => "foo")