最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Extra GET API call after update call - Stack Overflow

programmeradmin0浏览0评论

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.

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.

Share Improve this question edited Aug 27, 2018 at 8:48 handlerFive 87910 silver badges24 bronze badges asked Aug 27, 2018 at 8:38 Surabhi KSurabhi K 14410 bronze badges 0
Add a ment  | 

4 Answers 4

Reset to default 4

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.

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 e in handy if to know execution is successful.

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

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.

发布评论

评论列表(0)

  1. 暂无评论