node package manager
We need your input. Help make JavaScript better: Take the 2017 JavaScript Ecosystem survey »



npm node npm Travis


Funkster is a compositional server library. This package contains the basic combinators to write HTTP(S) servers. It allows to describe your api in a declarative, functional manner and compose it by using the existing combinators to write higher level ones.

There exists a repository with examples of how to build HTTP server apis with funkster here.

Typscript is used to illustrate the examples.


$ npm install funkster-http


$ npm install && npm run build


$ npm run test


This package introduces the HttpContext type which contains the request and response references and the HttpPipe which is every combinators basic signature.


Echo server

The following example demonstrates a basic echo server which just responds with the sent body of POST requests.

import * as http from 'http';
import { asRequestListener, body, Ok, POST } from 'funkster-http';
const echo = POST(body(buffer => Ok(String(buffer)))); 
const server = http.createServer(asRequestListener(greet));
// start the node HTTP server and send e.g. a POST with body 'Hello World!'. 

Basic routing and different HTTP verbs

The following example demonstrates basic routing and using different HTTP Verbs. All routes that have not been registered will return a 404.

import * as http from 'http';
import { choose } from 'funkster-core';
import { asRequestListener, body, GET, ifPath, Ok, parsePath, POST } from 'funkster-http';
interface Greeting {
  name: string;
const api =
      ifPath("/", () => Ok("Hello World!")),
      parsePath<Greeting>("/:name", params => Ok("Hello from GET, " +
      ifPath("/", () => body(name => Ok("Hello from POST, " + String(name))))
const server = http.createServer(asRequestListener(api));
// start the node HTTP server and send e.g. a GET to '$HOST/John'. 


Using HttpPipes in node or as connect middleware

Using asRequestListener on a HttpPipe returns a node compatible (req, res) => void callback which can be passed to http.createServer. Using asConnectMiddleware on a HttpPipe returns a connect compatible (req, res, next) => void callback which, for example, can be passed to app.use in express.

Using a node callback or connect middleware in Funkster

Using fromRequestListener on a (req, res) => void callback returns a HttpPipe which can then be combined with other Funkster combinators. Using fromConnectMiddleware on a (req, res, next) => void callback returns a HttpPipe which can then be combined with other Funkster combinators.


Icon funky by from the Noun Project.