{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreibidlxf25lgouy33q4jcxbksypjee3qi5rce7motaoxq554fwpbby",
"uri": "at://did:plc:pi6woz4d47bkuws673w2il2r/app.bsky.feed.post/3miuhgnazmrf2"
},
"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",
"Refactor into multi-package mono-repo by sillychipmunk · Pull Request #7 · jarlah/http-tower-hs · GitHub"
],
"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.\n\nEDIT2: have a PR up here if anyone is interested in looking at it. tried to make it as resusable as possible, and extensible, so it should be possible to use generically with anything not just http, and to implement more packages in the future for ex grpc etc. Refactor into multi-package mono-repo by sillychipmunk · Pull Request #7 · jarlah/http-tower-hs · GitHub",
"title": "Http-tower-hs — A Rust Tower-inspired middleware library for Haskell"
}