openapi-ts icon indicating copy to clipboard operation
openapi-ts copied to clipboard

[client-next] Create a server actions API for `POST` methods

Open GarciaLnk opened this issue 10 months ago • 1 comments

Description

In my use case, I want to make all requests to the API from the Next.js server side. Currently, the generated client works fine for retrieving data on server components, however sometimes it is needed to mutate data from a client component through server actions. In this case I would have to create a wrapper around the generated functions that would turn them into server actions (as described in https://github.com/hey-api/openapi-ts/issues/413#issuecomment-2193714720).

Ideally, these server actions would be automatically generated alongside the rest of the client, reducing the amount of boilerplate code. For example, the functions that call a POST method in sdk.gen.ts could be wrapped in an async function (with serializable arguments and return values), inside a actions.gen.ts (or whatever) file prefaced with use server.

GarciaLnk avatar Mar 18 '25 13:03 GarciaLnk

I see this feature has been requested for a while. Are there any updates on it or official workaround for now? @mrlubos @GarciaLnk

I have seen this also a workaround

https://github.com/hey-api/openapi-ts/issues/413#issuecomment-2193714720

GambetaClub avatar Oct 15 '25 07:10 GambetaClub