Skip to main content

fastro

ci

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@v0.8.2/mod.ts";
const server = new Fastro();
server.get("/", (req) => req.send("root"));
await server.listen();

How to use

This module uses the git release. If you want to pick a specific version, for example 0.8.2, then the full url is https://deno.land/x/fastro@v0.8.2/mod.ts. If you do not use the version, it will refer to master branch. Breaking changes may be made without warning.

Benchmarks

If performance is important to you, here are the Hello World benchmark results:

Framework Version Router? Avg Req
Deno http 1.0.5 13545.8
Fastro 0.8.2 11695
Fastify 2.14.1 9985.9
Oak 4.0.0 8612
Abc 1.0.0-rc10 7236.7
Node http 14.3.0 6167.5
Express 4.17.1 5785.1
PHP 7.3.11 5206.61
Python Flask 1.1.2 570.5

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());

Decorator

Another way to add a new property or function to the fastro instance and request object is to use a decorator. This is similar to the fastify decorator.

server
  .decorate((instance) => instance.ok = "ok")
  .decorate((instance) => instance.hello = (payload: string) => payload)
  .decorateRequest((req) => req.oke = "oke request");

server
  .get("/", (req) => req.send(server.ok))
  .get("/hello", (req) => req.send(server.hello("hello")))
  .get("/oke", (req) => req.send(req.oke));

Plugin

You can add new properties or functions to the fastro instance. You can also use all default instance functions, include decorator, 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);

Examples

Check this folder to find out how to: