{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreidqadtiycayj7hpvrfd6iyic5ybojaoik2tefv3ojt5ppy5k2vmnm",
"uri": "at://did:plc:pi6woz4d47bkuws673w2il2r/app.bsky.feed.post/3mistwrf467m2"
},
"path": "/t/http-tower-hs-a-rust-tower-inspired-middleware-library-for-haskell/13892#post_6",
"publishedAt": "2026-04-06T06:21:28.000Z",
"site": "https://discourse.haskell.org",
"tags": [
"@LaurentRDC"
],
"textContent": "something like this @LaurentRDC ?\n\n\n import Servant.Tower.Adapter\n import Tower.Middleware.Retry\n import Tower.Middleware.Timeout\n import Tower.Middleware.CircuitBreaker\n\n breaker <- newCircuitBreaker\n let config = CircuitBreakerConfig { cbFailureThreshold = 5, cbCooldownPeriod = 30 }\n env = withTowerMiddleware\n ( withRetry (exponentialBackoff 3 0.5 2.0)\n . withTimeout 5000\n . withCircuitBreaker config breaker\n ) (mkClientEnv manager baseUrl)\n result <- runClientM (getUsers <|> getHealth) env\n\n\nworking on it. Trying to see if it makes sense. I use an adapter approach now. Where http-tower-hs holds the main implementation and servant-tower-hs is just a clean and simple adapter. The question begs, will this work for other libraries as well? is it generic enough? with the current change I’m also able to do generic implementation like this (which sort of answers my question):\n\n\n import Tower\n\n -- Wrap a database query as a Service\n let dbService :: Service SQL.Query [SQL.Row]\n dbService = Service $ \\query -> do\n result <- try $ SQL.query conn query\n pure $ case result of\n Left err -> Left (TransportError err)\n Right rows -> Right rows\n\n -- Add resilience with the same middleware you'd use for HTTP\n breaker <- newCircuitBreaker\n let config = CircuitBreakerConfig { cbFailureThreshold = 5, cbCooldownPeriod = 30 }\n robust = withRetry (exponentialBackoff 3 0.5 2.0)\n . withTimeout 5000\n . withCircuitBreaker config breaker\n $ dbService\n\n result <- runService robust \"SELECT * FROM users\"\n\n\nwhich sort of should give the “aha” towards whether this is tied into http directly. The answer is no.\n\nEDIT: working on it now. Making it a mono repo and trying to make as much of the middlewares as generic if possible.",
"title": "Http-tower-hs — A Rust Tower-inspired middleware library for Haskell"
}