🚧 This documentation is work in progress and for an unreleased version of Fresh.
Routing
Routing defines which middlewares and routes should respond to a particular request.
const app = new App()
.get("/", () => new Response("hello")) // Responds to: GET /
.get("/other", () => new Response("other")) // Responds to: GET /other
.post("/upload", () => new Response("upload")); // Responds to: POST /upload
.get("/books/:id", (ctx) => {
// Responds to: GET /books/my-book, /books/cool-book, etc
const id = ctx.params.id
return new Response(`Book id: ${id}`));
})
.get("/blog/:post/comments", () => {
// Responds to: GET /blog/my-post/comments, /blog/hello/comments, etc
const post = ctx.params.post
return new Response(`Blog post comments for post: ${post}`)
})
.get("/foo/*", (ctx) => {
// Responds to: GET /foo/bar, /foo/bar/baz, etc
return new Response("foo"));
})
Fresh supports the full
URLPattern
syntax for setting pathnames.