From d24b5012811a1e7b67761d0e658763624e677be2 Mon Sep 17 00:00:00 2001 From: Joel Kaasinen Date: Fri, 15 Mar 2024 09:31:48 +0200 Subject: [PATCH] doc: handlers can be vars --- doc/advanced/dev_workflow.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/doc/advanced/dev_workflow.md b/doc/advanced/dev_workflow.md index 032ded69..cec7b0e6 100644 --- a/doc/advanced/dev_workflow.md +++ b/doc/advanced/dev_workflow.md @@ -147,3 +147,19 @@ Let's apply a small change to our ```ns3```. We'll replace our router by two dif And there you have it, dynamic during dev, performance at production. We have it all ! +## Var handlers + +You can use a var instead of a function as a `:handler`. This will +allow you to modify the handler function without rebuilding the reitit +router. + +For example: + +```clj +(def router + (ring/router + ["/ping" {:get #'my-ns/handler}])) +``` + +Now you can reload `my-ns` or redefine `my-ns/handler` and the router +will use the new definition automatically.