Solid start call
Just getting into solid start. Going through this documentation to try and get api routes set up so I can fetch data: https://docs.solidjs.com/solid-start/building-your-application/api-routes
I have two files that look like this
I can't seem to get it to call the
GET
(or POST
) route. Not sure where I'm going wrong. Thanks for any help!API routes - SolidDocs
Documentation for SolidJS, the signals-powered UI framework
12 Replies
You donβt need an explicit api route.
You can add
"use server"
at the top inside the async function and call that directly.
Like here:
https://docs.solidjs.com/solid-start/guides/data-fetching#passing-parameters-to-queriesData fetching - SolidDocs
Documentation for SolidJS, the signals-powered UI framework
But actually what you did should work nonetheless.
Did you ensure that the app runs in port 3001 all the time?
Did you ensure that the app runs in port 3001 all the time?I believe so? Me setup was
pnpm create solid@latest
(enabled solid start) and I ran pnpm i
and pnpm dev
. I specifically set the port to 3001. Do I need to start the api seperatly?Just to get you started again:
There were lots of little problems. Why are you using port
3001
for the APIβis something else hogging the default port of 3000
?Why are you using port 3001 for the APIβis something else hogging the default port of 3000?I always run my main project on port 3000. So when I'm trying out new stuff/mini projects (like this one) I use port 3001. I'll try what you sent, thank you. You sent the same code snippet twice. Was that intentional?
fixed
Much thanks
Using
and after updating
src/routes/index.tsx
it still works.That works, thank you so much!
Note how this accomplishes the same thing:
without having to implement an API route.
Thanks, the
{ message: 'Hello from the backend!' }
was mostly to prove that it's working. I have a DB and stuff I am going to be pulling data from (which I believe you can use what you posted if I'm using an orm?)
will work where
db.getPosts()
only exists on the server. "use server"
essentially creates an RPC call while (de)serialization is handled by seroval.