-
-
Notifications
You must be signed in to change notification settings - Fork 35
Description
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