Backbone.save POST instead of PUT

just a short question:

Having received a new instance of the model and issuing model.save() with the URL set to /api/store/category , Backbone returns POST. According to my information, he should use PUT, as indicated in this post "PUT or POST: REST of the Story" .

Who is right? BB or the author of this article?

+6
source share
1 answer

According to the documentation for the base station, saving the new model will result in a POST request, and saving the existing model (with identifier) ​​will emit a PUT request.

save model.save ([attributes], [options])
...
If the model is New, the save will "create" (HTTP POST), if the model already exists on the server, the save will be "update" (HTTP PUT).

And if you're wondering if Backbone should use POST to create, check

In light of these articles, I would say that in the context of Backbone verbs are correctly used:

  • saving a new model leads to a change in the system, a new URL is added, the action is not idempotent, it must be POST,
  • Saving a known model replaces the resource at the given URL, the action is idempotent, it must be PUT.
+13
source

Source: https://habr.com/ru/post/917955/


All Articles