Fork me on GitHub
#reitit
<
2020-05-29
>
Matheus Moreira10:05:46

hello, all. i am learning to use reitit and want to build routes for a restfull service. i thought that something like:

["/api/resources"
 {:get {...}
  :put {...}}
 ["/:res-id"
  {:get {...}
   :patch {...}}]]
would generate 4 routes: GET/PUT /api/resources and GET/PATCH /api/resources/:res-id but found out that this is not the case, only the two last routes are generated. what is the proper way to create the 4 routes? should i flatten the routes myself or is there another way to build these hierarchical routes?

ikitommi11:05:29

@matheus.emm the intermediate path fragments are not counted as endpoints. There is a PR ongoing to change that. Before it, you need to define the endpoints like this:

["/api/resources"
 [""
  {:get {...}
   :put {...}}
 ["/:res-id"
  {:get {...}
   :patch {...}}]]

Matheus Moreira11:05:51

@ikitommi, ok, understood. Maybe the documentation could be updated to make this point more obvious. When I read about this "empty" path I thought it was only to apply common data to a set of routes. Thanks for the clarification!

ikitommi11:05:31

would you like to update the docs for this?