farrow-express
Adapter for farrow-http
in Express app.
Installation
- npm
- Yarn
npm install farrow-express
yarn add farrow-express
Usage
Create a farrow-http
app first:
import { Http } from "farrow-http";
const http = Http();
http
.match({
pathname: "/test",
})
.use((data) => {
return Response.text(JSON.stringify(data));
});
And then create a Express app:
import express from "express";
const PORT = 3000;
const app = express();
app.get("/", (req, res) => {
res.send("Hello World!");
});
app.listen(PORT, () => {
console.log(`Example app listening at http://localhost:${PORT}`);
});
and combine them:
import express from "express";
import { Http, Response } from "farrow-http";
import { adapter } from "farrow-express";
const PORT = 3000;
const http = Http();
http
.match({
pathname: "/test",
})
.use((data) => {
return Response.text(JSON.stringify(data));
});
const app = express();
app.get("/", (req, res) => {
res.send("Hello World!");
});
app.use("/farrow", adapter(http));
app.listen(PORT, () => {
console.log(`Example app listening at http://localhost:${PORT}`);
});
Then, you can use work with farrow stack under route path /farrow
in a Express app.
API
Type Signature:
const adapter: (httpPipeline: HttpPipeline) => RequestHandler;
Learn more
Relative Module
- farrow-http: A Type-Friendly Web Framework.
- farrow-koa: Adapter for
farrow-http
in Koa app.
Sample
- farrow-sample/17-http-express: HTTP Server sample with Express.