npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@funkster/http

v1.0.0

Published

Funkster is a compositional server library. This package contains the basic http types and combinators.

Downloads

3

Readme

funkster-http

npm node npm Travis

Icon

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.

Install

$ npm install @funkster/http

Build

$ npm install && npm run build

Test

$ npm run test

Basics

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

Examples

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 =
  choose([
    GET(choose([
      ifPath("/", () => Ok("Hello World!")),
      parsePath<Greeting>("/:name", params => Ok("Hello from GET, " + params.name))
    ])),
    POST(
      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'.

Api

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.

Meta

Icon funky by iconsmind.com from the Noun Project.