T
TanStack2mo ago
absent-sapphire

Not Having DELETE / PUT breaks integrations with existing RESTful APIs

Context: I have an SSR server and client using tanstack start. I can define server functions as either get / post. Right now these server functions essentially wrap another backend API. Problem Unless server functions can make fully restful requests (POST, PUT, DELETE, GET), then I cannot fully integrate with an existing restful API that utilizes those methods. This to me is a production grade issue. i.e. I would imagine a lot of smaller projects don't need to wrap other APIs as much, but in a production scenario, server functions might want to proxy RESTful APIs and have full access to all http methods.
9 Replies
continuing-cyan
continuing-cyan2mo ago
you can use them all?
export const ServerRoute = createServerFileRoute("/api/$").methods({
HEAD: handle,
GET: handle,
POST: handle,
PUT: handle,
PATCH: handle,
DELETE: handle,
});
export const ServerRoute = createServerFileRoute("/api/$").methods({
HEAD: handle,
GET: handle,
POST: handle,
PUT: handle,
PATCH: handle,
DELETE: handle,
});
absent-sapphire
absent-sapphireOP2mo ago
was referring to server functions vs. serverFileRoutes
absent-sapphire
absent-sapphireOP2mo ago
No description
absent-sapphire
absent-sapphireOP2mo ago
No description
sunny-green
sunny-green2mo ago
not totally opposed to adding all verbs want to contribute this?
rare-sapphire
rare-sapphire2mo ago
I think forms only accept get/post. So probably will need some type of “magic” there to either show a ts error if you pass a delete function to a form, or I think rr7 automatically uses POST behind the scenes even if you select put/delete if js is not available
absent-sapphire
absent-sapphireOP2mo ago
Would we need to solve for that? Sounds like more an issue with choosing the right server fn to adhere to an existing spec Open to taking a look at what would be involved for this update
sunny-green
sunny-green2mo ago
yeah I don't see an issue with forms. just dont call a delete function with a form
extended-salmon
extended-salmon2mo ago
I have a question about the necessity of adding these methods to server functions. From my point of view, server functions are not expected to behave like regular API routes; they are more intended to be a "transparent" layer between client and server. I would also argue that server functions could always use the POST method, or at least have it as a default. It would simplify the implementation, make it a bit less verbose, be safer, and avoid some kind of confusion between server functions and API routes. In my Tanstack Start implementations, my front end (and other server functions) call the server functions, and the server functions call the API functions. It is a security concern: my front-end never calls the API directly to avoid exposing it. I accept I can be wrong in my arguments, and I could help implement these changes if it makes sense.

Did you find this page helpful?