-
I am looking for a way to call server-side functions, not necessarily when loading the page, but when a button is clicked in the front end. Right now I am using cloud functions to execute these kinds of functions, but I wonder if I can just use the server from sveltekit? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 7 replies
-
You can import a function that you've defined in your back end code, but I'm not sure that's exactly what you mean. |
Beta Was this translation helpful? Give feedback.
-
Sure. Make a server-side endpoint and |
Beta Was this translation helpful? Give feedback.
-
Thank you for all the answers. I went further to study how action forms and endpoints really work. I just couldn't believe that the endpoints would become a cloud function (in Vercel)! Just wow. I had to wrap my head around these concepts. So the answer to my question is yes. You can call with the click of a button any function that lives in the server (+server.ts, +page.ts, +page.server.ts) but with a slightly different method: either using form actions or calling the endpoint as @infovore said. thanks so much. I'll try to add a working example on the template I am building https://github.com/ctwhome/top-sveltekit |
Beta Was this translation helpful? Give feedback.
Sure. Make a server-side endpoint and
POST
to it (orGET
if you must...); or use a page endpoint and a an action, just like you would calling... any other server side function?