All Projects → fluture-js → Momi

fluture-js / Momi

Licence: mit
Monadic middleware

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Momi

Scriptum
A fool's scriptum on functional programming
Stars: ✭ 346 (+507.02%)
Mutual labels:  monad, algebraic-data-types
Functionaljava
Functional programming in Java
Stars: ✭ 1,472 (+2482.46%)
Mutual labels:  monad, algebraic-data-types
Purify
Functional programming library for TypeScript - https://gigobyte.github.io/purify/
Stars: ✭ 843 (+1378.95%)
Mutual labels:  monad, algebraic-data-types
Fluture
🦋 Fantasy Land compliant (monadic) alternative to Promises
Stars: ✭ 2,249 (+3845.61%)
Mutual labels:  monad, algebraic-data-types
Static Land
Specification for common algebraic structures in JavaScript based on Fantasy Land
Stars: ✭ 699 (+1126.32%)
Mutual labels:  monad, algebraic-data-types
Lambda
Functional patterns for Java
Stars: ✭ 737 (+1192.98%)
Mutual labels:  monad, algebraic-data-types
Witchcraft
Monads and other dark magic for Elixir
Stars: ✭ 864 (+1415.79%)
Mutual labels:  monad, algebraic-data-types
Guzzle Stopwatch Middleware
A Guzzle Stopwatch Middleware
Stars: ✭ 50 (-12.28%)
Mutual labels:  middleware
Circuit Breaker Monad
Circuit Breaker pattern as a monad
Stars: ✭ 52 (-8.77%)
Mutual labels:  monad
Egg Authz
egg-authz is an authorization middleware for Egg.js based on Casbin
Stars: ✭ 50 (-12.28%)
Mutual labels:  middleware
Graphql Factory
A toolkit for building GraphQL
Stars: ✭ 44 (-22.81%)
Mutual labels:  middleware
Guzzle Cache Middleware
A Guzzle Cache middleware
Stars: ✭ 50 (-12.28%)
Mutual labels:  middleware
Condor Framework
Framework for building GRPC services in Node JS. Include middleware, and more.
Stars: ✭ 52 (-8.77%)
Mutual labels:  middleware
Authorization
PSR7 Middleware for authorization
Stars: ✭ 50 (-12.28%)
Mutual labels:  middleware
Redux Electron Ipc
Redux Electron IPC Middleware
Stars: ✭ 54 (-5.26%)
Mutual labels:  middleware
Looli
a tiny web framework
Stars: ✭ 45 (-21.05%)
Mutual labels:  middleware
Koa Useragent
Koa user-agent middleware
Stars: ✭ 54 (-5.26%)
Mutual labels:  middleware
Rainbow
An Express router middleware for RESTful API base on file path.
Stars: ✭ 53 (-7.02%)
Mutual labels:  middleware
Proxykit
A toolkit to create code-first HTTP reverse proxies on ASP.NET Core
Stars: ✭ 1,063 (+1764.91%)
Mutual labels:  middleware
Aspnetcore Request Decompression
HTTP request decompression middleware for ASP.NET Core
Stars: ✭ 51 (-10.53%)
Mutual labels:  middleware

momi

Greenkeeper badge

Monadic Middleware

npm install --save monastic fluture momi

Middleware - specifically in the case of Connect, Express and Koa - is a mechanism which encodes several effects:

  • A build-up of state through mutation of the req parameter
  • An eventual response through mutation of the res parameter
  • Inversion of control over the continuation by means of calling the next parameter
  • Possible error branch by means of calling the next parameter with a value

If we would want to encode all of these effects into a data-structure, we could use a StateT(Future) -> StateT(Future) structure:

  • A build-up of state through the State monad
  • An eventual response through the right-sided value of Future
  • Inversion of control by passing the whole structure into a function
  • Possible error branch through the left-sided value of Future

In other words, the StateT(Future)-structure might be considered the Middleware monad. This packages exposes the Middleware monad, comprised of State from monastic and Future from Fluture. Besides the monad itself, it also exposes some utility functions and structures for practically applying Middleware. One such utility is the App class, which allows composition of functions over Middleware to be written more like what you are used to from middleware as it comes with Connect, Express or Koa.

Usage

import Z from 'sanctuary-type-classes';
import qs from 'querystring';

import {compose, constant} from 'monastic';
import {go, mount, get, put} from 'momi';

const queryParseMiddleware = go(function*(next) {
  const req = yield get;
  const query = qs.parse(req.url.split('?')[1]);
  yield put(Object.assign({query}, req));
  return yield next;
});

const echoMiddleware = Z.map(req => ({
  status: 200,
  headers: {'X-Powered-By': 'momi'},
  body: req.query.echo
}), get);

const app = compose(
  queryParseMiddleware,
  constant(echoMiddleware)
);

mount(app, 3000);

Examples

  • Readme the code from Usage, ready to run.
  • Express shows how to embed Momi within Express.
  • Bootstrap an extensive example showing application structure.
  • Real World how momi is being used in real life.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].