A minimalistic, pure HTTP framework for backend applications
npm install sawercreate-sawer-app.
bash
$ npm install sawer
`
Installing CLI package:
`bash
$ npm install sawer-cli -D
`
Getting started
Create a route:
`ts
// server/route.ts
import type { Request, Response } from 'sawer';
export async function GET(req: Request, res: Response) {
res.end('Hello, world!');
}
`
Create build:
`bash
$ sawer build
`
Run build:
`bash
$ 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.
`js
// 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('Hello, world!
');
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:
`bash
$ sawer build
$ node server.js
``