Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

httpf middleware? #201

Open
neezer opened this issue Nov 11, 2024 · 2 comments
Open

httpf middleware? #201

neezer opened this issue Nov 11, 2024 · 2 comments

Comments

@neezer
Copy link

neezer commented Nov 11, 2024

How could I add something like middleware to my httpf app? I'd like to set the session cookie on every request, but I haven't yet had an epiphany on how I might accomplish this... is there a commonly-understood pattern I could use here?

@neezer
Copy link
Author

neezer commented Nov 11, 2024

I came up with the following macro, but not sure if there's a better way?

(defmacro route [meta handler]
  ~(defn ,(gensym) ,meta [req data]
    (set-session-cookie req)
    (apply ,handler [req data])))

Used like:

(route
  {:path "/" :doc "homepage"}
  (fn [&]
    @[[:h1 "hello world"]]))

@sogaiu
Copy link
Contributor

sogaiu commented Nov 13, 2024

Possibly not much of a useful answer here, but FWIW, searching through various repositories, some of the results that turned up included:

All of the contained uses of spork/httpf seemed fairly simple and not along the lines of middleware AFAICT.

So:

is there a commonly-understood pattern I could use here

I suspect an answer to this might be "no". May be you are pioneering (^^;

It could be that the authors of those projects might have some ideas though?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants