@plant/http-adapter

1.4.0 • Public • Published

Plant HTTP Adapter


This handler connect Plant and native Node's HTTP server.

Install

Production version from NPM registry:

npm i @plant/http

Adapter has Plant as peer dependency so you need to install it too:

npm i @plant/plant

Usage

const http = require('http');
const Plant = require('@plant/plant');
const {createRequestHandler} = require('@plant/http-adapter');

const plant = new Plant();

// Send text response
plant.use('/greet', async function({res}) {
    res.body = 'Hello World';
});

// Build request handler
http.createServer(createRequestHandler(plant))
.listen(80);

Examples

API

createRequestHandler()

(plant:Plant, intermediate: Handler) -> HttpRequestListener

Return native HTTP server request handler, which pass request through intermediate handlers and then pass to the plant. Intermediate handlers have access to both HTTP (httpReq, httpRes) and Plant (req, res) requests and responses.

HttpRequestListener()

(req: http.Request, res: http.Response) -> void

This is standard request listener from Node.js HTTP built-in module.

License

MIT © Rumkin

/@plant/http-adapter/

    Package Sidebar

    Install

    npm i @plant/http-adapter

    Weekly Downloads

    24

    Version

    1.4.0

    License

    MIT

    Unpacked Size

    114 kB

    Total Files

    7

    Last publish

    Collaborators

    • rumkin