Skip to main content
Module

x/fastro/mod.ts>Fastro

Fast and simple web application framework for deno
Go to Latest
interface Fastro
import { type Fastro } from "https://deno.land/x/fastro@v0.82.2/mod.ts";

Properties

close: () => void

Immediately close the server listeners and associated HTTP connections.

record: Record<string, any>

Methods

use(...handler: Array<HandlerArgument>): Fastro

Add application level middleware

Example

import fastro from "../mod.ts";

const f = new fastro();
f.use((req: HttpRequest, _ctx: Context, next: Next) => {
  console.log(`${req.method} ${req.url}`);
  return next();
});

await f.serve();
get(path: string, ...handler: Array<HandlerArgument>): Fastro
post(path: string, ...handler: Array<HandlerArgument>): Fastro
put(path: string, ...handler: Array<HandlerArgument>): Fastro
delete(path: string, ...handler: Array<HandlerArgument>): Fastro
patch(path: string, ...handler: Array<HandlerArgument>): Fastro
options(path: string, ...handler: Array<HandlerArgument>): Fastro
head(path: string, ...handler: Array<HandlerArgument>): Fastro
hook(hook: Hook): Fastro

Allow you access Server, Request, and Info after Middleware, Routes, Pages, and Static File Processing. It can return Response, Promise<Response> or void.

Example

import fastro, { Fastro, Info } from "../mod.ts";

const f = new fastro();

f.hook((_f: Fastro, _r: Request, _i: Info) => new Response("Hello World"));

await f.serve();
static(path: string, options?: { maxAge?: number; folder?: string; referer?: boolean; }): Fastro

Allow you to access static files with custom path, folder, maxAge, and referer checking.

Example

import fastro from "../mod.ts";

const f = new fastro();

f.static("/static", { folder: "static", maxAge: 90, referer: true });

await f.serve();
page(
path: string,
element: Component,
...handler: Array<MiddlewareArgument>,
): Fastro

Allow you to define SSR page with custom path, element, and handler

Example

import fastro, { Context, HttpRequest } from "../mod.ts";
import user from "../pages/user.tsx";

const f = new fastro();

f.static("/static", { folder: "static", maxAge: 90 });

f.page("/", user, (_req: HttpRequest, ctx: Context) => {
    const options = {
      props: { data: "Guest" },
      status: 200,
      html: { head: { title: "React Component" } },
    };
    return ctx.render(options);
  },
);
await f.serve();
register(mf: ModuleFunction): Promise<Fastro>
getStaticFolder(): string
getStaticPath(): string
getDevelopmentStatus(): boolean
push(
method?: string,
path?: string,
...handler: Array<HandlerArgument>,
): Fastro

Add a handler directly

onListen(handler: ListenHandler): void
finished(): Promise<void> | undefined
getNest(): Nest
serve(): Promise<void>

Serves HTTP requests

If the server was constructed without a specified port, 8000 is used.