0.0.7 • Published 5 years ago
red-panda-web v0.0.7
Red Panda Web
A functional web server written with rxjs.
Documentation
Quick Start
Install red-panda-web
:
$ npm install --save-prod red-panda-web
Add the following to a file:
import { RedPandaWeb, handleErrorsAndSend, get, produce, routes } from "red-panda-web";
function main() {
const app = new RedPandaWeb();
app.requestSource$
.pipe(
routes(
get("/", o$ =>
o$.pipe(
produce(r => {
r.headers["Content-Type"] = "text/plain";
r.status = 200;
r.body = Buffer.from("Hello world!\n");
})
)
)
),
handleErrorsAndSend()
)
.subscribe();
app.listenAndServe(s => console.log("Listening at:", s.address()));
}
if (require.main) {
main();
}
Run the script, and then call:
$ curl localhost:3000
# Outputs >>> Hello world!
Developing
Command | Description |
---|---|
npm run package | Clean lib/ , lint source, run tests, compile to lib . |
npm run test:watch | Run test suite in --watch mode. |
npm test | Run test suite. |