Grails REST with @Resource - PUT is not updating

2019-08-09 08:59发布

I'm learning grails (2.4.0) right now and have a weird problem with automatically generated REST methods.

So, i have a simple domain

@Resource(uri = '/unit', formats = ['json'])
class Unit {
    String name;
}

I can successfully list/create/delete instances with GET/POST/DELETE methods, but PUT method does nothing:

curl -i -X PUT -H "Content-Type: application/json" -d '{"name":"fail", "id":65}' localhost:8080/app/unit/65
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Location: http://localhost:8080/app/unit/65
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Sun, 01 Jun 2014 09:25:02 GMT

{"class":"app.Unit","id":65,"name":"test"}

subsequent GET requests will also return name:test instead of name:fail

What i can be doing wrong?

标签: rest grails
1条回答
【Aperson】
2楼-- · 2019-08-09 09:23

This is a bug which only relates to updates (not to newly created instances). I have worked up the fix and we will have this fix included in 2.4.1. See https://jira.grails.org/browse/GRAILS-11462.

The short of it is that updates are being done with the request parameters, even if the request has a body. The fix is to change that so when the update is done, if the request has a body then the body is used and if it does not, the request a parameters are used.

Sorry for the trouble and thanks for the input.

查看更多
登录 后发表回答