Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request(plugin-api): catch-all routes #707

Open
1 task done
SerenModz21 opened this issue Mar 3, 2025 · 0 comments
Open
1 task done

request(plugin-api): catch-all routes #707

SerenModz21 opened this issue Mar 3, 2025 · 0 comments

Comments

@SerenModz21
Copy link

Is there an existing issue or pull request for this?

  • I have searched the existing issues and pull requests

Feature description

Catch-all routes have wide support in frameworks (Nuxt, Next.js, Hono, Express, and so on). As the API plugin is based on Nuxt routing, I think they would be a great addition to the plugin's routing.

Desired solution

For the most part, I will be going off the Nuxt docs: https://nuxt.com/docs/guide/directory-structure/server#catch-all-route

Route Matching

If we were to have src/routes/foo/[...slug].ts, the route would match anything after /foo/. In terms of a regex matcher, this would look something like /foo/(.+) (the / would be escaped if it was real regex).

Accessing Params

If, for example, we passed /foo/bar/baz into the URL, the result would be accessed via request.params.slug. As for how the returned data would look, the two popular ways look like this:

  • Nuxt returns a string: bar/baz
  • Next.js returns an array: ['bar', 'baz']

Either way, no matter which gets returned, we can always get to the other by using String.split() or Array.join().

Method Accessibility

I believe catch-all routes allow any HTTP method by default. However, should we want to limit which of those methods can be used, RouteOptions.methods could be utilized.

Alternatives considered

To keep with the flow of how routes are structured, no other alternatives have been considered.

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant