Understanding server actions
Unanswered
Nile tilapia posted this in #help-forum
Nile tilapiaOP
I had a question about server actions about when to use them. If I am making a lot of POST/GET Requests to a 3rd party service, how would I reason about using the server? Right now my understanding is if I have any private resource I should hide behind my backend, but if I don't, I should just keep these requests on the client for speed purposes. Is my understanding correct here or is there something I'm missing out on?
6 Replies
@Nile tilapia I had a question about server actions about when to use them. If I am making a lot of POST/GET Requests to a 3rd party service, how would I reason about using the server? Right now my understanding is if I have any private resource I should hide behind my backend, but if I don't, I should just keep these requests on the client for speed purposes. Is my understanding correct here or is there something I'm missing out on?
yeah your understanding is correct. you only need a server action if you need to do something that can't be done in the client. e.g. accessing a secret key that you need to pass to an external API or calling server-side exclusive methods, like
revalidatePath@Rafael Almeida yeah your understanding is correct. you only need a server action if you need to do something that can't be done in the client. e.g. accessing a secret key that you need to pass to an external API or calling server-side exclusive methods, like `revalidatePath`
American Crow
Correct me if i am wrong.
OP is saying "If i am making a lot of POST/GET Requets to 3rd party service ... I should just keep these requets on the client fo rspeed purposes"
In a perfect world the GET Requests would be done by a server component for optimal performance, no?
OP is saying "If i am making a lot of POST/GET Requets to 3rd party service ... I should just keep these requets on the client fo rspeed purposes"
In a perfect world the GET Requests would be done by a server component for optimal performance, no?
@American Crow Correct me if i am wrong.
OP is saying *"If i am making a lot of POST/GET Requets to 3rd party service ... I should just keep these requets on the client fo rspeed purposes"*
In a perfect world the GET Requests would be done by a server component for optimal performance, no?
if you need this data during the rendering of the page then yes it will be faster to do it directly on the server-side, but since they are asking about server actions I am assuming that these requests are fired in response of an user interaction, something that only happens on the client
but even then the definitive answer depends on a lot of factors. if you have a single request making it directly to the API from the client would be faster. but if you have multiple requests to the API and their servers are far from the client, then it would be faster to do a single request to your own server then it handles everything there
(which also depends on the distance from your server to the API server)
@Rafael Almeida if you need this data during the rendering of the page then yes it will be faster to do it directly on the server-side, but since they are asking about server actions I am assuming that these requests are fired in response of an user interaction, something that only happens on the client
American Crow
Okay thank you. Just a question which came up in my mind reading this. Just to have the mental model in check
.
.