@plant/http-adapter
v1.4.0
Published
Plant web server node.js HTTP adapter
Downloads
17
Readme
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