RESTful grails application: DRYing up UrlMapping

邮差的信 提交于 2019-12-03 13:24:50

I would recommend the following mapping:

"/rest/url/$id?"(resource:"urlRest")

Below is the HTTP method to action mapping that this would create for the urlRestController:

GET         show
PUT         update
POST        save
DELETE      delete

I see why you might want to map /rest/url POST to save and /rest/url/id PUT to update, but that goes against the meaning of those verbs. A PUT should be the only way to add a new url and POST the only way to update a url. Doing it the way you have laid out would work and might be the best way if your constraint is to keep your current controller code untouched. However, my guess is that you controller might already be coded to handle the default mappings just fine (update/delete give error if no id, show redirects to list if no id, etc.).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!