Fastro
Fast and simple web application framework for deno
Basic usage
import { fastro } from "https://deno.land/x/fastro@v0.33.0/server/mod.ts";
const app = fastro();
app.get("/", () => {
return new Response("Hello world!");
});
await app.serve();
Custom port
import { fastro } from "https://deno.land/x/fastro@v0.33.0/server/mod.ts";
const app = fastro();
app.get("/", () => {
return new Response("Hello world!");
});
await app.serve({ port: 3000 });
Route parameters
import {
fastro,
getParam,
getParams,
} from "https://deno.land/x/fastro@v0.33.0/server/mod.ts";
const app = fastro();
app.get("/:id/user/:name", (req: Request) => {
const params = getParams(req);
const param = getParam("id", req);
return new Response(JSON.stringify({
params,
param,
}));
});
await app.serve();
Middleware
import {
ConnInfo,
fastro,
Next,
} from "https://deno.land/x/fastro@v0.33.0/server/mod.ts";
const app = fastro();
function middleware(req: Request, connInfo: ConnInfo, next: Next) {
console.log("url=", req.url);
console.log("remoteAddr=", connInfo.remoteAddr);
next();
}
function handler(_req: Request, _connInfo: ConnInfo) {
return new Response("Hello world!");
}
app.get("/", middleware, handler);
await app.serve();