Deserve Quick Start
Import
// main.ts
import { createApp, createRouter, response } from "https://deno.land/x/deserve/mod.ts";Create App
/// ....
const app = createApp()Create Router
/// ....
const router = createRouter<typeof app>()typeof app gives the router better type safety
Add Routes
Routes take in a path that follows the URLPattern API which is a Web standard and a series of handlers that can return a response to complete the request or return nothing to go to the next handler
/// ....
router.get("/", (req, ctx) => {
return response("Hello World")
})response(...) is just an alias for new Response(...) which is a web standard
Append the router to the app and start the server
/// ....
app
.use(router.routes())
.listen({
port: 8080
})Now run the app
deno run --allow-net main.tsComplete Example
import { createApp, createRouter, response } from "https://deno.land/x/deserve/mod.ts";
// Create App
const app = createApp()
// Create Router
const router = createRouter<typeof app>()
// Define Routes
router.get("/", (req, ctx) => {
return response("Hello World")
})
app
// Append Router to App
.use(router.routes())
// Start the Server
.listen({
port: 8080
})