路由 POST 和 GET 请求:控制器还是调度程序?
当您制作 Web 应用程序时,您经常需要在 HTTP POST 请求的给定 URL 上发生与 HTTP GET 请求不同的事情。我正在 Pylons 中制作一个网络应用程序,我遇到了这个问题。
在我的 URL 调度程序 (路由) 中还是在我的控制器中区分 POST 和 GET 是否更好?哪些因素会使这些选项中的一个比另一个更好?
如果我使用 Django,答案会有所不同吗?铁轨? ASP.NET MVC?
When you're making a web app, you frequently need different things to happen at a given URL for HTTP POST requests than happen for HTTP GET requests. I am making a web app in Pylons, and I'm encountering this question.
Is it better to distinguish between POST and GET in my URL dispatcher (Routes) or in my controllers? What factors would make one of these options better than the other?
Would the answer be different if I were using Django? Rails? ASP.NET MVC?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的代码应该有明确的责任分离,因此路由/调度代码应该控制我的请求发送到的位置。这只是很好的设计,不应该因为语言而改变。
代码的读者只需阅读路由代码就可以知道预期的内容以及它将去往何处。如果您稍后改变主意,您可以更改路由代码而无需触摸控制器。
然后控制器只负责处理请求,这使得它更简单,更容易理解,错误更少并且更容易更改。
Good code should have clean separation of responsibility therefore the routing/dispatching code should control where I request is sent. This is just good design and shouldn't change because of the language.
A reader of the code can tell just from reading the routing code what is expected and where it will go. If you change your mind later on, you can changing the routing code without touching the controllers.
The controller is then only responsibile for handling the request which makes it simpler, making it easier to understand, have fewer bugs and easier to change.