API Routes with Nextjs 13 app structure
Unanswered
Brown bear posted this in #help-forum
Brown bearOP
Hey there, are API routes disabled with new app structure? If yes is there a way to call server actions from outside?
13 Replies
Brown bear
@Brown bear dont think for now that we can call server action from outside
Barbary Lion
Why do you want to call server actions from outside ? Just call the API? My understanding is Server Actions are just syntactic sugar for API calls in your RSCs
Brown bearOP
I was under the impression that server action replace API endpoints in nextjs
Barbary Lion
I'm no expert, but I think the idea is instead of making traditional API endpoints, you create a server action which allows you to bypass a) making an API endpoint, b) calling it... For the times when the API endpoint is made for just that reason (and not to be called from outside like a traditional endpoint), just a quick way to add form submissions and similar in RSC
Definitely could be wrong, I'm not 100% on my understanding
So instead of making an API endpoint for just 1 form, and then calling it from just that 1 form. (you now have the 2 sides of the API interaction), you just make a simple server action, and it's quick code, lightweight, and feels like frontend stuff
the big picture vision is that route handlers are only necessary if you need to expose an API endpoint to external services and for everything in your own application to use Server Actions
but as of now, it's pretty standard to use route handlers to create API endpoints that your client components use (especially considering that server actions are experimental and not feature complete)
Barbary Lion
Jarrah, do you know if server actions are providing responses ?
Success, Errors, input validation feedback ?
Success, Errors, input validation feedback ?
Barbary Lion
I.e Login component, being able to validate, or respond to successful logins
ok, when i tried a month ago, it was not able, which made it difficult to use, so switched to client components for that