http4js

Release notes

View full release notes

Table of Contents

Intro

http4js is a thin layer around node http. Within this layer we can happily unit test our routing logic and easily spin up any function (Req) => Promise<Res> as a server.

Basic Server

We can route a path to a handler and start it as a server:

routes("GET", "/path", async (req) => ResOf(200))
    .asServer()
    .start();

Then we can make a call to this endpoint

HttpClient(new Request("GET", "http://localhost:3000/path"))
    .then(response => console.log(response));
     
/*
Response {
  headers: 
   { date: 'Sun, 25 Mar 2018 09:24:43 GMT',
     connection: 'close',
     'transfer-encoding': 'chunked' },
  body: '',
  status: 200 }
*/

What’s the big idea?

Next: Handlers and Filters