{"id":23651496,"url":"https://github.com/athanclark/wai-transformers","last_synced_at":"2025-11-15T17:30:16.917Z","repository":{"id":56882383,"uuid":"42907508","full_name":"athanclark/wai-transformers","owner":"athanclark","description":"Simple parameterization of Wai's Application type","archived":false,"fork":false,"pushed_at":"2018-03-22T14:11:09.000Z","size":16,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-26T01:02:14.761Z","etag":null,"topics":["haskell","wai","wai-transformers"],"latest_commit_sha":null,"homepage":null,"language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/athanclark.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-22T02:53:01.000Z","updated_at":"2018-11-27T20:24:22.000Z","dependencies_parsed_at":"2022-08-21T00:20:08.610Z","dependency_job_id":null,"html_url":"https://github.com/athanclark/wai-transformers","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athanclark%2Fwai-transformers","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athanclark%2Fwai-transformers/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athanclark%2Fwai-transformers/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/athanclark%2Fwai-transformers/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/athanclark","download_url":"https://codeload.github.com/athanclark/wai-transformers/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239609730,"owners_count":19668006,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["haskell","wai","wai-transformers"],"created_at":"2024-12-28T16:38:07.599Z","updated_at":"2025-11-15T17:30:16.834Z","avatar_url":"https://github.com/athanclark.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"wai-transformers\n================\n\nSimple parameterization of Wai's `Application` and `Middleware` types.\n\n\n## Overview\n\nWai's `Application` type is defined as follows:\n\n```haskell\ntype Application = Request -\u003e (Response -\u003e IO ResponseReceived) -\u003e IO ResponseReceived\n```\n\nThis is great for the server - we can just `flip ($)` the middlewares together to get\nan effectful server. However, what if we want to encode useful information in our\nmiddleware chain / end-point application? Something like a `ReaderT Env` environment,\nwhere useful data like a universal salt, current hostname, or global mutable references can\nbe referenced later if it were wedged-in.\n\nThe design looks like this:\n\n```haskell\ntype ApplicationT m = Request -\u003e (Response -\u003e IO ResponseReceived) -\u003e m ResponseReceived\n```\n\nNow we can encode MTL-style contexts with applications we write\n\n```haskell\ntype MiddlewareT m = ApplicationT m -\u003e ApplicationT m\n\n\ndata AuthConfig = AuthConfig\n  { authFunction :: Request -\u003e Either AuthException (Response -\u003e Response)\n  }\n\nsimpleAuth :: ( MonadReader AuthConfig m\n              , MonadError AuthException m\n              ) =\u003e MiddlewareT m\nsimpleAuth app req resp = do\n  auth \u003c- authFunction \u003c$\u003e ask\n  case auth req of\n    Left e = throwError e\n    Right f = app req (resp . f)\n\nsimpleAuth' :: Middleware\nsimpleAuth' app req resp =\n  eReceived \u003c- runExceptT $ runReaderT (simpleAuth app req resp) myAuthConfig\n  case eReceived of\n    Left e = resp $ respondLBS \"Unauthorized!\"\n    Right r = return r\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fathanclark%2Fwai-transformers","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fathanclark%2Fwai-transformers","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fathanclark%2Fwai-transformers/lists"}