Replies: 1 comment 2 replies
-
HI @qubit55, Please find a hack below using a decorator to remove outdated routes that reference the The purpose of the Just a reminder that decorators are applied right-to-left. This means that the I hope this helps. (ns fa
(:import [fastapi :as f]
[uvicorn :as uv]))
(defonce app (f/FastAPI))
(defn update-route! [app path]
(fn [func]
(let [routes (seq (.. app -router -routes))]
(doseq [route routes]
(when (and (= path (.-path route)) (not= (.-endpoint route) func))
(.remove (.. app -router -routes) route))))
func))
(defn root {:async true
:decorators [(update-route! app "/")
(.get app "/")]}
[]
{"message" "Hi there"})
(comment
(def server (future (uv/run app ** :host "127.0.0.1" :port 8000)))
(.. app -router -routes)
(.. app -router -routes clear)
;;
) |
Beta Was this translation helpful? Give feedback.
-
Hello,
I'm trying to use an interactive workflow with FastAPI - spinning up a server from within the REPL in a separate thread so it's non-blocking. Ideally, every time I redefine a handler, I expect the server to pick it up automatically. Unfortunately, that doesn’t work out of the box with FastAPI. From what I understand, it creates a static routing table that doesn’t allow dynamic updates, which kind of kills the interactive development experience.
That said, I’ve come up with a workaround:
Right now, every time I redefine a handler, I have to call update-routes. It works, but I’m not sure I like this approach.
Any suggestions on how to make this process smoother?
Beta Was this translation helpful? Give feedback.
All reactions