#Full differences between server functions and api routes
10 messages · Page 1 of 1 (latest)
You can’t use api routes like a function
I think most of the time I would just use server functions
Except for webhooks and things like that
API routes are for when you need static routes that behave similar to Express and Fastify. Think something like a "public" API or an endpoint to receive webhooks (like from Stripe).
The server functions are more for creating dynamic endpoints, which when accessed to executes code on the server. Think of these endpoints as private as in their URLs are not static and can change between deployments.
Just a disclaimer, by private I do not mean "secure". You'd still have to appl security practices to both API routes and Server functions (rate-limiting, authorization, etc).
thanks
what are the differences between server functions in tanstack start and 'use server' directives in react 19? functionally its quite the same, its just slightly different way of creating them?
Server functions are the "concept".
The createServerFn util is an abstraction the automatically appends 'use server'
cool, I thought that might be the case but have not checked in the source -_-