httpland/http-router

Nested route

Closed this issue ยท 3 comments

The current routing table only accepts flat URL patterns.

Since URLs represent hierarchies, routing tables should also be able to represent hierarchies.

However, this should be a pure syntax sugar for flat URL pattern.
Therefore, nested URL pattern will be flat at initialization time.

Expected:

import { createRouter } from "https://deno.land/x/http_router/mod.ts";
createRouter({
  "/api": {
    "/status": () => new Response("OK"),
    "/hello": {
      GET: () => new Response("world"),
    },
  },
"/api/test": () => new Response("test")
});

concern

  • Duplicate URL pattern
  • Decreased readability

Duplicate URL pattern

No duplicate URL patterns occurred when keying the flat URL pattern.

However, there is a possibility that the flat URL pattern and the nested URL pattern could be identical.

If identical URL patterns are detected, an error is thrown early.

import { createRouter } from "https://deno.land/x/http_router/mod.ts";

createRouter({
  "/api": {
    "/hello": () => new Response(null),
  },
  "/api/hello": () => new Response(null)
}); // throw Error

Decreased readability

Readability concerns remain when nested URLs and method handlers are mixed.

import { createRouter } from "https://deno.land/x/http_router/mod.ts";

createRouter({
  "/api": {
    GET: () => new Response(null),

    "/hello": () => new Response(null),
  },
});
  • GET /api
  • ALL /api/hello

Also, the catch all method cannot be expressed.

import { createRouter } from "https://deno.land/x/http_router/mod.ts";

createRouter({
  "/api": {
    "ALL?": () => new Response(null),

    "/hello": () => new Response(null),
  },
});

Need to handle special keys such as the ALL key.

๐ŸŽ‰ This issue has been resolved in version 1.2.0-beta.2 ๐ŸŽ‰

The release is available on GitHub release

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€

๐ŸŽ‰ This issue has been resolved in version 1.2.0 ๐ŸŽ‰

The release is available on GitHub release

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€

๐ŸŽ‰ This issue has been resolved in version 1.0.0-beta.6 ๐ŸŽ‰

The release is available on GitHub release

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€