1
votes

I'm using grails 2.3.9. I implemented a controller that extends RestfulController (let's call it FooController, and I also have a Foo domain class).

In my controller, I override createResource and getParametersToBind to accomodate my business logic.

In URLMappings.groovy I added the following :

"/foo"(resource:"foo")

In my ajax client, I POST a json query with the following request headers :

Accept:application/javascript, application/json
Content-Type:application/json

However, I get a 404 response.

I tried to copy the save method from RestfulController into FooController so I could step-debug through it, and noticed it goes all the way until the last line of the withFormat closure through the '*' mime type.

Now, if I change that line from

respond instance, [status: CREATED]

to

render instance as JSON

it works...

Is there a problem with the headers I send in my request ?

Note : It works fine when I add { format = 'json' } in my URLMappings' resource declaration, but shouldn't the request headers be enough ?

1

1 Answers

2
votes

I managed to make this work by editing Config.groovy and setting this :

grails.mime.disable.accept.header.userAgents = []

I'd still be interested in understanding why the default is to prevent browsers to consume rest services through ajax calls...