sawer
v0.0.3
Published
A minimalistic, pure HTTP framework for backend applications
Downloads
531
Readme
The easiest way to get start is by using
create-sawer-app
.
Installation
Installing the core package:
$ npm install sawer
Installing CLI package:
$ npm install sawer-cli -D
Getting started
Create a route:
// server/route.ts
import type { Request, Response } from 'sawer';
export async function GET(req: Request, res: Response) {
res.end('Hello, world!');
}
Create build:
$ sawer build
Run build:
$ sawer start
Creating custom server
A final build exposes many methods that can be used to create a custom server.
Including sawer
which is the main route handler for incoming requests.
// server.js
import { sawer, config } from '../dist/index.js';
import http from 'node:http';
const server = http.createServer();
const port = config.port || 3000;
server.on('request', async (req, res) => {
// some custom logic
if (req.url === '/') {
res.end('<h1>Hello, world!</h1>');
return;
}
await sawer(req, res);
});
server.listen(port, () => {
console.log(`Listening on http://localhost:${port}`);
});
In order to run it, create a build and execute the file:
$ sawer build
$ node server.js
Disclaimer
⚠ This is still being developed. It's not ready for production yet.
License
This project is licensed under the MIT License ❤️