Registering API Endpoints on SolidStart

Hi everyone! I’m exploring ways to programmatically register API endpoints in SolidStart without relying on FileRoutes. My goal is to fully control the paths manually instead of using the file-based routing system. I know it’s possible to do this using a middleware like so:
import { createMiddleware } from "@solidjs/start/middleware";

export default createMiddleware({
onRequest: [
event => {
// Custom logic here
}
]
});
import { createMiddleware } from "@solidjs/start/middleware";

export default createMiddleware({
onRequest: [
event => {
// Custom logic here
}
]
});
While this works, I’m wondering if there’s a simpler or more straightforward alternative. Additionally, does the Solid Router support adding API endpoints directly, or is there a recommended way to handle API routing with it? Using a middleware as shown above, is there a built-in utility in SolidStart to match routes and extract query parameters from the request? If so, how can it be used within the middleware? I’d appreciate any guidance, examples, or tips. Thanks in advance!
2 Replies
peerreynders
peerreynders3w ago
and extract query parameters from the request
The event has a nativeEvent property which is an H3Event which exposes a URL object (MDN).
Event Object - h3
Event object carries an incoming request and context.
GitHub
h3/src/types/event.ts at 4be78d70ce7eb0abd37143086d359dd535abf3d1 ·...
⚡️ Minimal H(TTP) framework built for high performance and portability - unjs/h3
snnsnn
snnsnnOP3w ago
Thanks, I know the event object has request, repsonse etc, but i am asking if there is a way to match a route, and parse query parameters, as I am trying to avoid external dependencies and manual work, and I see h3 router is not exposed: https://h3.unjs.io/guide/router

Did you find this page helpful?