Reputation: 87
I have defined my domain objects
class Product implements Serializable{
String sku
static hasMany = [images: MediaContent]
}
class MediaContent implements Serializable{
[...]
}
and their REST controllers that extends RestFulController. In particular, the ProductRestController is as follows: class ProductRestController extends RestfulController {
static responseFormats = ['json']
ProductRestController(){
super(Product)
JSON.registerObjectMarshaller(Product){
return [
id: it.id,
media: createLink(controller:"mediaRest", id:it.imageId)
]
}
The url mapping is very simple as
"/rest/product" (resources:"productRest")
"/rest/media" (resources:"mediaRest")
The issue is that the generated link with createLink
directive is not in the rest format /rest/media/1
but /rest/media/index?id=1
.
Both of these urls work, when invoked, but only the ?id=
version is generated.
I have tried also createLink with resource
property, but nothing works.
How could I achieve that?
Upvotes: 1
Views: 96
Reputation: 1062
You can make change in UrlMappings.groovy
"/rest/product/$action/$id"(controller: 'productRest')
"/rest/media/$action/$id"(controller: 'mediaRest')
Upvotes: 1