Attributes
Includes Deno configuration
Repository
Current version released
3 years ago
Versions
- v0.94.1Latest
- v0.94.0
- v0.93.10
- v0.93.9
- v0.93.8
- v0.93.7
- v0.93.6
- v0.93.5
- v0.93.4
- v0.93.3
- v0.93.2
- v0.93.1
- v0.93.0
- v0.92.2
- v0.92.1
- v0.92.0
- v0.91.1
- v0.91.0
- v0.90.0
- v0.89.4
- v0.89.3
- v0.89.2
- v0.89.1
- v0.89.0
- v0.88.3
- v0.88.2
- v0.88.1
- v0.88.0
- v0.87.3
- v0.87.2
- v0.87.1
- v0.87.0
- v0.86.1
- v0.86.0
- v0.85.1
- v0.85.0
- v0.84.30
- v0.84.29
- v0.84.28
- v0.84.27
- v0.84.26
- v0.84.25
- v0.84.24
- v0.84.23
- v0.84.22
- v0.84.21
- v0.84.20
- v0.84.19
- v0.84.18
- v0.84.17
- v0.84.16
- v0.84.15
- v0.84.14
- v0.84.13
- v0.84.12
- v0.84.11
- v0.84.10
- v0.84.9
- v0.84.8
- v0.84.7
- v0.84.6
- v0.84.5
- v0.84.4
- v0.84.3
- v0.84.2
- v0.84.1
- v0.84.0
- v0.83.5
- v0.83.4
- v0.83.3
- v0.83.2
- v0.83.1
- v0.83.0
- v0.82.3
- v0.82.2
- v0.82.1
- v0.82.0
- v0.81.5
- v0.81.4
- v0.81.3
- v0.81.2
- v0.81.1
- v0.81.0
- v0.80.5
- v0.80.4
- v0.80.3
- v0.80.2
- v0.80.1
- v0.80.0
- v0.79.3
- v0.79.2
- v0.79.1
- v0.79.0
- v0.78.2
- v0.78.1
- v0.78.0
- v0.77.11
- v0.77.10
- v0.77.9
- v0.77.7
- v0.77.8
- v0.77.6
- v0.77.5
- v0.77.4
- v0.77.3
- v0.77.2
- v0.77.1
- v0.77.0
- v0.76.3
- v0.76.2
- v0.76.1
- v0.76.0
- v0.75.13
- v0.75.12
- v0.75.11
- v0.75.10
- v0.75.9
- v0.75.8
- v0.75.7
- v0.75.6
- v0.75.5
- v0.75.4
- v0.75.3
- v0.75.2
- v0.75.1
- v0.75.0
- v0.74.9
- v0.74.8
- v0.74.7
- v0.74.6
- v0.74.5
- v0.74.4
- v0.74.3
- v0.74.2
- v0.74.1
- v0.74.0
- v0.73.0
- v0.72.2
- v0.72.1
- v0.72.0
- v0.71.2
- v0.71.1
- v0.71.0
- v0.70.5
- v0.70.4
- v0.70.3
- v0.70.2
- v0.70.1
- v0.70.0
- v0.69.4
- v0.69.3
- v0.69.2
- v0.69.1
- v0.69.0
- v0.68.2
- v0.68.1
- v0.68.0
- v0.67.2
- v0.67.1
- v0.67.0
- v0.66.0
- v0.65.5
- v0.65.4
- v0.65.3
- v0.65.2
- v0.65.1
- v0.65.0
- v0.64.4
- v0.64.4
- v0.64.3
- v0.64.2
- v0.64.1
- v0.64.0
- v0.63.9
- v0.63.8
- v0.63.7
- v0.63.6
- v0.63.5
- v0.63.4
- v0.63.4
- v0.63.3
- v0.63.2
- v0.63.1
- v0.63.1
- v0.63.0
- v0.62.16
- v0.62.15
- v0.62.14
- v0.62.13
- v0.62.12
- v0.62.11
- v0.62.10
- v0.62.9
- v0.62.8
- v0.62.7
- v0.62.6
- v0.62.5
- v0.62.4
- v0.62.3
- v0.62.2
- v0.62.1
- v0.62.0
- v0.61.3
- v0.61.2
- v0.61.1
- v0.61.0
- v0.60.1
- v0.60.0
- v0.59.2
- v0.59.1
- v0.59.0
- v0.58.4
- v0.58.3
- v0.58.2
- v0.58.1
- v0.58.0
- v0.57.6
- v0.57.5
- v0.57.4
- v0.57.3
- v0.57.2
- v0.57.1
- v0.57.0
- v0.56.2
- v0.56.1
- v0.56.0
- v0.55.0
- v0.54.0
- v0.53.2
- v0.53.1
- v0.53.0
- v0.52.0
- v0.51.2
- v0.51.1
- v0.51.0
- v0.50.0
- v0.49.0
- v0.48.1
- v0.48.0
- v0.47.0
- v0.46.0
- v0.45.0
- v0.44.0
- v0.43.0
- v0.42.1
- v0.42.0
- v0.41.3
- v0.41.2
- v0.41.1
- v0.41.0
- v0.40.1
- v0.40.0
- v0.39.0
- v0.38.0
- v0.37.1
- v0.37.0
- v0.36.0
- v0.35.0
- v0.34.0
- v0.33.1
- v0.33.0
- v0.32.0
- v0.31.2
- v0.31.1
- v0.31.0
- v0.30.60
- v0.30.59
- v0.30.58
- v0.30.57
- v0.30.56
- v0.30.55
- v0.30.54
- v0.30.53
- v0.30.52
- v0.30.51
- v0.30.50
- v0.30.49
- v0.30.48
- v0.30.47
- v0.30.46
- v0.30.45
- v0.30.44
- v0.30.43
- v0.30.42
- v0.30.41
- v0.30.40
- v0.30.39
- v0.30.38
- v0.30.37
- v0.30.36
- v0.30.35
- v0.30.34
- v0.30.33
- v0.30.32
- v0.30.31
- v0.30.30
- v0.30.29
- v0.30.28
- v0.30.27
- v0.30.26
- v0.30.25
- v0.30.24
- v0.30.23
- v0.30.22
- v0.30.21
- v0.30.20
- v0.30.19
- v0.30.18
- v0.30.17
- v0.30.16
- v0.30.15
- v0.30.14
- v0.30.13
- v0.30.12
- v0.30.11
- v0.30.10
- v0.30.9
- v0.30.8
- v0.19.1
- v0.19.0
- v0.18.0
- v0.17.0
- v0.16.0
- v0.15.2
- v0.15.1
- v0.15.0
- v0.14.5
- v0.14.4
- v0.14.3
- v0.14.2
- v0.14.1
- v0.14.0
- v0.13.15
- v0.13.14
- v0.13.13
- v0.13.12
- v0.13.11
- v0.13.10
- v0.13.9
- v0.13.8
- v0.13.7
- v0.13.6
- v0.13.5
- v0.13.4
- v0.13.3
- v0.13.2
- v0.13.1
- v0.13.0
- v0.12.4
- v0.12.3
- v0.12.2
- v0.12.1
- v0.12.0
- v0.11.4
- v0.11.3
- v0.11.2
- v0.11.1
- v0.11.0
- v0.10.2
- v0.10.1
- v0.10.0
- v0.9.0
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.1
- v0.7.0
- v0.6.3
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.5
- v0.5.4
- v0.5.3
- v0.5.2
- v0.5.1
- v0.5.0
- v0.4.2
- v0.4.1
- v0.4.0
- v0.3.7
- v0.3.6
- v0.3.5
- v0.3.4
- v0.3.3
- v0.3.2
- v0.3.1
- v0.3.0
- v0.2.13
- v0.2.12
- v0.2.11
- v0.2.10
- v0.2.9
- v0.2.8
- v0.2.7
- v0.2.6
- v0.2.5
- v0.2.4
- v0.2.3
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.0
Fastro
Fast and simple web application framework for deno.
With near-native perfomance, you can manage your routing, middlewares, and dependencies cleanly. You can also take advantage of existing the standard deno objects and methods: Request, Response, Headers, and Cookie.
Examples
- Getting Started
- Custom Port
- HTML response
- Set, Get, and Delete a Cookie
- Render with Eta Template Engine
- Routing
- Route Parameters
- Router Middleware
- Router Middleware with Array
- Application Level Middleware
- Application Level Middleware with Array
- Route Level Middleware
- Route Level Middleware with Array
- SQLite and Dependency Injection
Getting started
import application from "https://deno.land/x/fastro@v0.51.2/server/mod.ts"
const app = application()
app.get("/", () => "Hello world")
await app.serve()
deno run -A https://deno.land/x/fastro@v0.51.2/examples/main.ts
Custom port
import application from "https://deno.land/x/fastro@v0.51.2/server/mod.ts"
const app = application()
app.get("/", () => "Hello world!")
await app.serve({ port: 3000 })
deno run -A https://deno.land/x/fastro@v0.51.2/examples/custom_port.ts
HTML Response
import application from "https://deno.land/x/fastro@v0.51.0/server/mod.ts"
const app = application()
app.get("/", () => {
return new Response("<html> Hello world </html>", {
status: 200,
headers: {
"content-type": "text/html",
},
})
})
console.log("Listening on: http://localhost:8000")
await app.serve()
deno run -A https://deno.land/x/fastro@v0.51.2/examples/html_response.ts
Render with Eta Template Engine
import application from "https://deno.land/x/fastro@v0.51.2/server/mod.ts"
import { render } from "https://deno.land/x/eta@v1.12.3/mod.ts"
const app = application()
const headers = new Headers()
headers.set("Content-Type", "text/html charset=UTF-8")
app.get("/", () => {
const html = <string> render(
"<h4>The answer to everything is <%= it.answer %></h4>",
{
answer: 42,
},
)
return new Response(html, { headers })
})
console.log("Listening on: http://localhost:8000")
await app.serve()
deno run -A https://deno.land/x/fastro@v0.51.2/examples/render.ts
Set, Get, and Delete a Cookie
import {
Cookie,
deleteCookie,
getCookies,
setCookie,
} from "https://deno.land/std@0.133.0/http/cookie.ts"
import application from "https://deno.land/x/fastro@v0.51.2/server/mod.ts"
const app = application()
app.post("/", () => {
const headers = new Headers()
const cookie: Cookie = { name: "Space", value: "Cat" }
setCookie(headers, cookie)
return new Response(JSON.stringify(cookie), { headers })
})
app.get("/", (req: Request) => {
const headers = req.headers
const cookies = getCookies(headers)
return new Response(JSON.stringify(cookies))
})
app.delete("/", () => {
const headers = new Headers()
deleteCookie(headers, "Space")
const cookies = getCookies(headers)
return new Response(JSON.stringify(cookies), {
headers,
})
})
console.log("Listening on: http://localhost:8000")
await app.serve()
deno run -A https://deno.land/x/fastro@v0.51.2/examples/cookies.ts
Routing
import application from "https://deno.land/x/fastro@v0.51.2/server/mod.ts"
const app = application()
app.get("/abcd", () => new Response("/abcd"))
app.get("/ef?gh", () => new Response("/ef?gh"))
app.get("/ij+kl", () => new Response("/ij+kl"))
app.get("/mn*op", () => new Response("mn*op"))
app.get("/qr(st)?u", () => new Response("qr(st)?u"))
app.get(/v/, () => new Response("/v/"))
app.get(/.*fast$/, () => new Response("/.*fast$/"))
await app.serve()
deno run -A https://deno.land/x/fastro@v0.51.2/examples/routing.ts
Route parameters
import application, {
getParam,
getParams,
} from "https://deno.land/x/fastro@v0.51.2/server/mod.ts"
const app = application()
app.get("/:id/user/:name", (req: Request) => {
const params = getParams(req)
return new Response(JSON.stringify({ params }))
})
app.get("/post/:id", (req: Request) => {
const param = getParam("id", req)
return new Response(param)
})
await app.serve()
deno run -A https://deno.land/x/fastro@v0.51.2/examples/route_params.ts
Router Middleware
import application, {
ConnInfo,
Next,
router,
} from "https://deno.land/x/fastro@v0.51.2/server/mod.ts"
const app = application()
const r = router()
const middleware = (_req: Request, _connInfo: ConnInfo, next: Next) => {
console.log("v2 - 1")
next()
}
r.get("/", () => new Response("Get"))
.post("/", () => new Response("Post"))
.put("/", () => new Response("Put"))
.delete("/", () => new Response("Delete"))
app.use("/v1", r)
app.use("/v2", middleware, r)
await app.serve()
deno run -A https://deno.land/x/fastro@v0.51.2/examples/router_middleware.ts
Router Middleware with Array
import application, {
ConnInfo,
Next,
router,
} from "https://deno.land/x/fastro@v0.51.2/server/mod.ts"
const app = application()
const r = router()
const middlewares = [(_req: Request, _connInfo: ConnInfo, next: Next) => {
console.log("v2 - 1")
next()
}, (_req: Request, _connInfo: ConnInfo, next: Next) => {
console.log("v2 - 2")
next()
}]
r.get("/", () => new Response("Get"))
.post("/", () => new Response("Post"))
.put("/", () => new Response("Put"))
.delete("/", () => new Response("Delete"))
app.use("/v1", r)
app.use("/v2", middlewares, r)
await app.serve()
deno run -A https://deno.land/x/fastro@v0.51.2/examples/router_middleware_with_array.ts
Application Level Middleware
import application, {
ConnInfo,
Next,
} from "https://deno.land/x/fastro@v0.51.2/server/mod.ts"
const app = application()
app.use((_req: Request, _conn: ConnInfo, next: Next) => {
console.log("app middleware #1")
next()
})
app.use((_req: Request, _conn: ConnInfo, next: Next) => {
console.log("app middleware #2")
next()
})
app.use((_req: Request, _conn: ConnInfo, next: Next) => {
console.log("app middleware #3")
next()
}, (_req: Request, _conn: ConnInfo, next: Next) => {
console.log("app middleware #4")
next()
})
app.get("/", () => new Response("App level #1"))
await app.serve()
deno run -A https://deno.land/x/fastro@v0.51.2/examples/application_level_middleware.ts
Application Level Middleware with Array
import application, {
ConnInfo,
Next,
} from "https://deno.land/x/fastro@v0.51.2/server/mod.ts"
const app = application()
const middlewares = [(_req: Request, _conn: ConnInfo, next: Next) => {
console.log("middleware #1")
next()
}, (_req: Request, _conn: ConnInfo, next: Next) => {
console.log("middleware #2")
next()
}, (_req: Request, _conn: ConnInfo, next: Next) => {
console.log("middleware #3")
next()
}, (_req: Request, _conn: ConnInfo, next: Next) => {
console.log("middleware #4")
next()
}]
app.use(middlewares)
app.get("/", () => new Response("App level #1"))
await app.serve()
deno run -A https://deno.land/x/fastro@v0.51.2/examples/application_level_middleware_with_array.ts
Route Level Middleware
import application, {
ConnInfo,
Next,
} from "https://deno.land/x/fastro@v0.51.2/server/mod.ts"
const app = application()
const middlewares = (_req: Request, _conn: ConnInfo, next: Next) => {
console.log("middleware #1")
next()
}
app.get("/", middlewares, () => new Response("App level #1"))
await app.serve()
deno run -A https://deno.land/x/fastro@v0.51.2/examples/route_level_middleware.ts
Route Level Middleware with Array
import application, {
ConnInfo,
Next,
} from "https://deno.land/x/fastro@v0.51.2/server/mod.ts"
const app = application()
const middlewares = [(_req: Request, _conn: ConnInfo, next: Next) => {
console.log("middleware #1")
next()
}, (_req: Request, _conn: ConnInfo, next: Next) => {
console.log("middleware #2")
next()
}, (_req: Request, _conn: ConnInfo, next: Next) => {
console.log("middleware #3")
next()
}, (_req: Request, _conn: ConnInfo, next: Next) => {
console.log("middleware #4")
next()
}]
app.get("/mnop", middlewares, () => new Response("Route level middleware #3"))
await app.serve()
deno run -A https://deno.land/x/fastro@v0.51.2/examples/route_level_middleware_with_array.ts
SQLite and Dependency Injection
import application, { dependency } from "https://deno.land/x/fastro@v0.51.2/server/mod.ts"
import { DB } from "https://deno.land/x/sqlite@v3.3.0/mod.ts"
const app = application()
const db = new DB("test.db")
const deps = dependency()
deps.set("hello", () => "Hello world")
deps.set("db", db)
app.use(deps)
app.get("/", () => {
type FunctionType = () => string
const fn = <FunctionType> app.getDeps("hello")
return new Response(fn())
})
app.post("/name", () => {
const db = <DB> app.getDeps("db")
db.query(`CREATE TABLE IF NOT EXISTS people (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT)`)
const names = ["Peter Parker", "Clark Kent", "Bruce Wayne"]
for (const name of names) {
db.query("INSERT INTO people (name) VALUES (?)", [name])
}
return new Response(JSON.stringify(names))
})
app.get("/name", () => {
const db = <DB> app.getDeps("db")
const res = db.query("SELECT name FROM people")
return new Response(JSON.stringify(res))
})
console.log("Listening on: http://localhost:8000")
await app.serve()
deno run -A https://deno.land/x/fastro@v0.51.2/examples/deps_injection.ts