{"id":20208416,"url":"https://github.com/fluture-js/momi","last_synced_at":"2025-07-26T11:40:49.058Z","repository":{"id":57159906,"uuid":"55833590","full_name":"fluture-js/momi","owner":"fluture-js","description":"Monadic middleware","archived":false,"fork":false,"pushed_at":"2021-04-06T12:38:42.000Z","size":260,"stargazers_count":58,"open_issues_count":2,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-05-23T10:22:40.681Z","etag":null,"topics":["algebraic-data-types","fluture","middleware","monad"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fluture-js.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-09T08:24:43.000Z","updated_at":"2024-02-23T16:07:48.000Z","dependencies_parsed_at":"2022-09-08T20:21:31.405Z","dependency_job_id":null,"html_url":"https://github.com/fluture-js/momi","commit_stats":null,"previous_names":["avaq/idealist"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluture-js%2Fmomi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluture-js%2Fmomi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluture-js%2Fmomi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fluture-js%2Fmomi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fluture-js","download_url":"https://codeload.github.com/fluture-js/momi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248222367,"owners_count":21067768,"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":["algebraic-data-types","fluture","middleware","monad"],"created_at":"2024-11-14T05:35:31.534Z","updated_at":"2025-04-10T12:56:22.306Z","avatar_url":"https://github.com/fluture-js.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# momi\n\n**Mo**nadic **Mi**ddleware\n\n\u003e `npm install --save monastic fluture momi`\n\nMiddleware - specifically in the case of Connect, Express and Koa - is a\nmechanism which encodes several effects:\n\n- **A build-up of state** through mutation of the `req` parameter\n- **An eventual response** through mutation of the `res` parameter\n- **Inversion of control** over the continuation by means of calling the\n  `next` parameter\n- **Possible error branch** by means of calling the `next` parameter with\n  a value\n\nIf we would want to encode all of these effects into a data-structure, we\ncould use a `StateT(Future) -\u003e StateT(Future)` structure:\n\n- **A build-up of state** through the `State` monad\n- **An eventual response** through the right-sided value of `Future`\n- **Inversion of control** by passing the whole structure into a function\n- **Possible error branch** through the left-sided value of `Future`\n\nIn other words, the `StateT(Future)`-structure might be considered the\nMiddleware monad. This packages exposes the Middleware monad, comprised of\n`State` from [monastic][] and `Future` from [Fluture][]. Besides the\nmonad itself, it also exposes some utility functions and structures for\npractically applying Middleware. One such utility is the `App` class,\nwhich allows composition of functions over Middleware to be written more\nlike what you are used to from middleware as it comes with Express or Koa.\n\n## Usage\n\n### Node\n\n```console\n$ npm install --save momi\n```\n\nOn Node 12 and up, this module can be loaded directly with `import` or\n`require`. On Node versions below 12, `require` or the [esm][]-loader can\nbe used.\n\n### Deno and Modern Browsers\n\nYou can load the EcmaScript module from various content delivery networks:\n\n- [Skypack](https://cdn.skypack.dev/momi@1.0.0)\n- [JSPM](https://jspm.dev/momi@1.0.0)\n- [jsDelivr](https://cdn.jsdelivr.net/npm/momi@1.0.0/+esm)\n\n### Old Browsers and Code Pens\n\nThere's a [UMD][] file included in the NPM package, also available via\njsDelivr: https://cdn.jsdelivr.net/npm/momi@1.0.0/dist/umd.js\n\nThis file adds `momi` to the global scope, or use CommonJS/AMD\nwhen available.\n\n## Usage Example\n\n```js\nimport Z from 'sanctuary-type-classes';\nimport qs from 'querystring';\nimport http from 'http';\n\nimport {compose, constant} from 'monastic';\nimport {go, mount, get, put} from 'momi';\n\nconst queryParseMiddleware = go (function* (next) {\n  const req = yield get;\n  const query = qs.parse (req.url.split ('?')[1]);\n  yield put (Object.assign ({query}, req));\n  return yield next;\n});\n\nconst echoMiddleware = Z.map (req =\u003e ({\n  status: 200,\n  headers: {'X-Powered-By': 'momi'},\n  body: req.query.echo,\n}), get);\n\nconst app = compose (\n  queryParseMiddleware,\n  constant (echoMiddleware)\n);\n\nmount (http, app, 3000);\n```\n\n## Examples\n\n- **[Readme][example-1]** the code from [Usage](#usage), ready to run.\n- **[Express][example-2]** shows how to embed Momi within Express.\n- **[Bootstrap][example-3]** an example showing application structure.\n- **[Real World][example-4]** how momi is being used in real life.\n\n[monastic]: https://github.com/dicearr/monastic\n[Fluture]: https://github.com/fluture-js/Fluture\n[example-1]: https://github.com/fluture-js/momi/tree/master/examples/readme\n[example-2]: https://github.com/fluture-js/momi/tree/master/examples/express\n[example-3]: https://github.com/fluture-js/momi/tree/master/examples/bootstrap\n[example-4]: https://github.com/Avaq/node-server-skeleton/tree/master/src/bootstrap\n[esm]: https://github.com/standard-things/esm\n[UMD]: https://github.com/umdjs/umd\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffluture-js%2Fmomi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffluture-js%2Fmomi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffluture-js%2Fmomi/lists"}