does implementing grails rest controllers needs changes in the UrlMappings?

StackOverflow https://stackoverflow.com/questions/23592520

  •  20-07-2023
  •  | 
  •  

Вопрос

I am trying to imeplement a rest controller in grails 2.3.7. I have a simple controller, same actions as of a scaffolded one, nothing special.

My problem is I am not able to call show, update, delete and save actions via:

GET to localhost:8080/proj/domain/1

PUT/DELETE to localhost:8080/proj/domain/1

POST to localhost:8080/proj/domain

However it works when I add this to the url in UrlMappings.groovy

"/$controller/$action?/$id?(.$format)?"{
        action = [POST:"save",GET:'show',DELETE:"delete"]
    }

Im following with the grails doc's '8.1.5 Implementing REST controllers'. Based on my understanding of it, it should work without doing further configurations outside of the controller. Is modifying the url mappings necessary?

Это было полезно?

Решение

Yes adding a REST controller requires you to add a URL mapping for the resource, defining it as either singular or multi resource. Example:

“/foo”(resource:”foo”)

Or

“/foos”(resources:”foo”)

You can run url-mappings-report to see the URL mappings this produces

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top