I have a bunch of insert, update, and delete operations I need to execute via Ajax. Which of the following would be a better approach?
-
Individual methods for each function (e.g. delete_foo, insert_foo, update_foo, delete_bar, insert_bar, update_bar, etc.)
-
A “master” method and just pass a parameter to distinguish between operations.
A benefit of #2’s approach would be that common things in the individual methods, such as validation or id decryption, etc. could be consolidated. However, it would also mean this master method would fairly large.
Having a master method call the individual method wouldn’t be such a great idea, I think. The reason is that the individual methods, if stripped of the common tasks now handled by the master method, are one-liner codes (for the most part).
An alternative to both of these methods is to use the REST rules. This makes use of the other HTTP Methods other than GET and POST.
For example
More details can be found here http://en.wikipedia.org/wiki/Representational_State_Transfer#RESTful_web_services.