Fastro is web framework for developers obsessed with performance and simplicity.
It is inspired by Fastify & Express.
import { Fastro } from "https://deno.land/x/fastro/mod.ts";
const server = new Fastro();
server.get("/", (req) => req.send("root"));
await server.listen();
Benchmarks
If performance is important to you, here are the Hello World
benchmark results:
Framework | Version | Router? | Avg Req |
---|---|---|---|
Abc | 1.0.0-rc10 | ✓ | 11548.2 |
Deno http |
1.0.5 | ✗ | 18078.8 |
Express | 4.17.1 | ✓ | 7161.55 |
Fastify | 2.14.1 | ✓ | 13821.8 |
Fastro | 0.7.0 | ✓ | 14980.8 |
Node http |
14.3.0 | ✗ | 16491.41 |
Oak | 4.0.0 | ✓ | 11246.6 |
PHP | 7.3.11 | ✗ | 6211.82 |
Python Flask | 1.1.2 | ✓ | 568 |
Check this folder to see the details.
Middleware
You can add new properties or functions to the default request
. This is similar to the express middleware.
const middleware = (req: Request, done: Function) => {
req.oke = () => req.send("oke");
done();
};
server
.use(middleware)
.get("/", (req) => req.oke());
Plugin
You can add new properties or functions to the fastro instance. You can also use all default instance functions, include create routes & middleware. This is similar to the fastify plugin.
const routes = function (fastro: Fastro, done: Function) {
fastro
.get("/", (req) => req.send("root"))
.post("/", (req) => req.send("post"))
.put("/", (req) => req.send("put"))
.delete("/", (req) => req.send("delete"));
done();
};
server.register(routes);
How to use
This module uses the git release. If you want to pick a specific version, for example 0.7.0
, then the full url is https://deno.land/x/fastro@0.7.0/mod.ts
. If you do not use the version, it will refer to master
branch and breaking changes may be made without warning.
Examples
Check this folder to find out how to:
- change default port & add optional listen callback
- send simple text & json data
- get url parameters
- get payload from post method
- set custom http headers & status
- change the request object by creating a middleware
- create simple jwt auth
- create middleware
- create decorator to add new property
- create router with plugin
- create nested plugin
- create simple REST API
- create simple REST API with JWT