Spring Data REST doesn't like the Accept
headers sent by jQuery.
jQuery sends these headers :
Accept:application/json, text/javascript, */*; q=0.01
And if you try queries like this :
curl -v -XGET -H "Accept:application/json, text/javascript, */*; q=0.01" http://localhost:8080/api/employees/
it will fail as a 404, but if you change it by removing the text/javascript
part :
curl -v -XGET -H "Accept:application/json, */*; q=0.01" http://localhost:8080/api/employees/
this one works.
You can override the default Accept
headers used by jQuery by using the $.ajaxSetup
method, or you can simply override these settings when you query your API.
$.ajax({
url : "http://localhost:8080/api/employees",
accepts: {json:'application/json'}
})
Now about the why, I think there's a problem in Spring Data REST here :
where the Accept
header is matched, and I think it may be due to the fact that text/javascript
doesn't exists for SpringData REST.