ring

Matt Ielusic 2025-02-08T22:07:12.404289Z

Hello! I have a question about Ring’s design. Why are middlewares implemented as higher-order functions? I was asked this a while back, when I was explaining my app’s middleware chain to someone, and I could sort of reverse-engineer a sensible answer — “they compose easily & are a natural abstraction for working with request and/or response” — but I wasn’t 100% sure.

Matt Ielusic 2025-02-09T19:14:19.015339Z

Interesting. Thanks!

weavejester 2025-02-08T23:51:36.178199Z

If you represent a handler as a function that takes in a request and returns a response, and if middleware is something that modifies the request, then in a functional language the most direct representation is a function that takes a handler function and returns a new handler function with some augmented behaviour.

👍🏽 1