Extra GET API call after update call

Viewed 394

As the frontend application has its own state, now the user updated his/her contact and the frontend state got updated and PUT API is called to update with the current state.

So while updating the user contact details through PUT call, should another GET call be made to fetch the user details or should the current state is enough for the frontend.

Just curious what is the advised pattern to follow.

4 Answers

Your PUTrequest should send a 200 ok so you know that the data frontside is now valid.

You could of course (this is what I do in some instances), is send the object back as a response of your PUT request with a 200 ok. With this object you can update your view as needed, ensuring that the object is exactly the same as the one on the server side.

A GET is not needed in this case.

After update(PUT call) you should make GET call to get the details from DB and display in the front end.

So that the user will get to know that the details are successfully updated.

OR

if you want to show update success message then in the backend you can return the updated values in PUT API call response and you can use this response to show details without making GET API call again.

OR else

Based on PUT call success response you can show the details that you set in the state without making a GET call

Another get request is not necessary, If you really want to maintain the state from backend (which is also not necessary), you can respond from the server to the PUT Request with the state. This may come in handy if to know execution is successful.

Not required.However,in the PUT request itself you can send the changed state.And you can concatenate/update the frontend state with the db state using filter method.In order to keep your frontend state intact with the db.

Related