Sugar for reitit routes. Lets you:
/users
2b. a unary route, e.g. /user/{id}A sugared route definition might be:
[[:my-app.endpoint.user]]
This would expand to:
[["/user" {:name :users ::ns :my-app.endpoint.user ::type :collection :id-key :id}] ["/user/{id}" {:name :user ::ns :my-app.endpoint.user ::type :member :id-key :id}]]
Here's how you'd apply a map of options to many routes:
[{:ctx {:foo :bar}} [:my-app.endpoint.user] [:my-app.endpoint.post]
{} ;; resets "shared" options to an empty ma [:my-app.endpoint.vote]]
This would expand to:
[["/user" {:name :users ::ns :my-app.endpoint.user ::type :collection :ctx {:foo :bar} :id-key :id}] ["/user/{id}" {:name :user ::ns :my-app.endpoint.user ::type :member :ctx {:foo :bar} :id-key :id}] ["/post" {:name :posts ::ns :my-app.endpoint.post ::type :collection :ctx {:foo :bar} :id-key :id}] ["/post/{id}" {:name :post ::ns :my-app.endpoint.post ::type :member :ctx {:foo :bar} :id-key :id}]
;; vote routes do not include the :ctx key ["/vote" {:name :votes ::ns :my-app.endpoint.vote ::type :collection :id-key :id}] ["/vote/{id}" {:name :vote ::ns :my-app.endpoint.vote ::type :member :id-key :id}]]
Sugar for reitit routes. Lets you:
1. Specify a map of options that apply to a group of routes
2. Transform names (usually namespace names) into reitit
routes that include both:
2a. a collection routes, e.g. `/users`
2b. a unary route, e.g. `/user/{id}`
## Basic expansion
A sugared route definition might be:
[[:my-app.endpoint.user]]
This would expand to:
[["/user" {:name :users
::ns :my-app.endpoint.user
::type :collection
:id-key :id}]
["/user/{id}" {:name :user
::ns :my-app.endpoint.user
::type :member
:id-key :id}]]
## Common option map
Here's how you'd apply a map of options to many routes:
[{:ctx {:foo :bar}}
[:my-app.endpoint.user]
[:my-app.endpoint.post]
{} ;; resets "shared" options to an empty ma
[:my-app.endpoint.vote]]
This would expand to:
[["/user" {:name :users
::ns :my-app.endpoint.user
::type :collection
:ctx {:foo :bar}
:id-key :id}]
["/user/{id}" {:name :user
::ns :my-app.endpoint.user
::type :member
:ctx {:foo :bar}
:id-key :id}]
["/post" {:name :posts
::ns :my-app.endpoint.post
::type :collection
:ctx {:foo :bar}
:id-key :id}]
["/post/{id}" {:name :post
::ns :my-app.endpoint.post
::type :member
:ctx {:foo :bar}
:id-key :id}]
;; vote routes do not include the :ctx key
["/vote" {:name :votes
::ns :my-app.endpoint.vote
::type :collection
:id-key :id}]
["/vote/{id}" {:name :vote
::ns :my-app.endpoint.vote
::type :member
:id-key :id}]](expand-route pair)(expand-route [ns opts :as pair] delimiter)In a pair of [n m], if n is a keyword then the pair is treated as a name route and is expanded. Otherwise the pair is returned as-is (it's probably a regular reitit route).
delimiter is a regex used to specify what part of the name to
ignore. By convention Sweet Tooth expects you to use names like
:my-app.backend.endpoint.user, but you want to just use user to
generate paths and route names - that's what the delimiter is for.
In a pair of [n m], if n is a keyword then the pair is treated as a name route and is expanded. Otherwise the pair is returned as-is (it's probably a regular reitit route). `delimiter` is a regex used to specify what part of the name to ignore. By convention Sweet Tooth expects you to use names like `:my-app.backend.endpoint.user`, but you want to just use `user` to generate paths and route names - that's what the delimiter is for.
(expand-routes pairs)(expand-routes pairs delimiter)(expand-routes pairs delimiter keywordize-ig-refs-cljs)Returns vector of reitit-compatible routes from compact route syntax
delimiter is a regex used to split the namespace "base" from its
domain component: foo.endpoint.user -> user
keywordize-ig-refs-cljs will replace all integrant refs with simple
keywords in the cljs output. this is so that the frontend won't try
to resolve the refs.
Returns vector of reitit-compatible routes from compact route syntax `delimiter` is a regex used to split the namespace "base" from its domain component: `foo.endpoint.user` -> `user` `keywordize-ig-refs-cljs` will replace all integrant refs with simple keywords in the cljs output. this is so that the frontend won't try to resolve the refs.
(ksubs k)full string representation of a keyword: :x/y => "x/y" :y => "y"
full string representation of a keyword: :x/y => "x/y" :y => "y"
(slash name)replace dots with slashes in namespace to create a string that's route-friendly
replace dots with slashes in namespace to create a string that's route-friendly
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |