import { createRequestListener } from '@hullo/node'

This creates a function you can provide to http.createServer or https.createServer.

Both request body and response body are streams of string | ArrayBuffer.

Following example creates a HTTP server on each request and returns a response that consists of a request method, request path and request body - a simple echo service.

import * as http from "http";
import { of, flatMap } from "@hullo/core";
import { createRequestListener } from "@hullo/node";
createRequestListener(async request => ({
status: 200,
headers: {},
body: of([
of<ArrayBuffer | string>(`ECHO\n`),
of<ArrayBuffer | string>(`Method: ${request.method}\n`),
of<ArrayBuffer | string>(`Path: ${request.url}\n`),
]).pipe(flatMap(v => v))

And the response will look like:

> curl -F 'data=DATA_DATA_DATA_DATA' http://localhost:81
Method: POST
Path: /
Content-Disposition: form-data; name="data"

To fully read the example see also: