๐Ÿงญ Dynamic & Wildcard Routes in Tirne

This example demonstrates how to use dynamic parameters (e.g., :id) and wildcard splats (e.g., *) in your route definitions with tirne.

Match dynamic paths like /user/:id or /blog/* and access the values through the params argument.

๐Ÿ”ง Example Code

import { Server, json } from "tirne";
import type { Route } from "tirne";

const routes: Route[] = [
  {
    method: "GET",
    path: "/user/:id",
    handler: (req, params) => {
      return json({ userId: params?.id });
    },
  },
  {
    method: "GET",
    path: "/blog/*",
    handler: (req, params) => {
      return json({ path: params?.["*"] });
    },
  },
];

const server = new Server(routes);

export default {
  fetch: (req: Request) => server.fetch(req),
};

๐Ÿงช Functionality Check

Try these curl commands to verify dynamic and wildcard routing:

1. โœ… Access /user/123

curl http://localhost:3000/user/123
{ "userId": "123" }

2. โœ… Access /blog/2025/06/tech/startup

curl http://localhost:3000/blog/2025/06/tech/startup
{ "path": "2025/06/tech/startup" }