Flaska is a micro web-framework for node. It is designed to be fast, simple and lightweight, and is distributed as a single file module with no dependencies.
Heavily inspired by koa and koa-router it takes liberties of implementing most of the common functionality required for most sites without sacrificing anything. And the fact that the footprint for this is much smaller than koa while also being more powerful and faster shows the testament that is flaska.
## Installation
```
$ npm install flaska
```
## Hello Flaska
```js
import { Flaska } from '../flaska.mjs'
const flaska = new Flaska()
flaska.get('/', function(ctx) {
ctx.body = 'Hello Flaska';
})
// flaska.listen(3000);
flaska.listenAsync(3000).then(function() {
console.log('listening on port 3000')
}, function(err) {
console.error('Error listening:', err)
})
```
## Router/Handlers
Flaska supports all the common verbs out of the box:
*`flaska.get(url, [middlewares], handler)`
*`flaska.post(url, [middlewares], handler)`
*`flaska.put(url, [middlewares], handler)`
*`flaska.delete(url, [middlewares], handler)`
*`flaska.options(url, [middlewares], handler)`
*`flaska.patch(url, [middlewares], handler)`
Example:
```
flaska.get('/path/to/url', async function(ctx) {
// Perform action
})
```
In addition, each route can have none, one or many middlewares:
In cases where the response body is a pipe object (detected from the existance of `.pipe` property), flaska will automatically pipe it for you. In addition, if a file stream is used, it will read the extension of the file being streamed and automatically fill in the mime-type for you in the `Content-Type` header.
ctx.body = new FileResponse('./test/test.txt', stat)
})
})
```
This performs a real file stream support, uses pipes and supports all the HTTP shenanigans when it comes to dealing with files, including sending proper etag header, supporting partial response and lots of other things. This is one of the few libraries that actually implements full HTTP partial and etag support in a proper way, almost all other have one or two quirks that don't follow the spec properly.