Accept header of */* incorrect for json?


#1

I’ve just setup a new EmberJS and Rails4 project. I’m using the default DS.RESTAdapter to fetch records from the server. The Accept header it is sending is application/json, text/javascript, */*; q=0.01. Because of the */*, the server returns html (see this gist).

I’ve solved this for my application with:

DS.RESTAdapter.reopen({
  headers: { 
    "Accept": "application/json, text/javascript; q=0.01"
  }
});

Is this a bug in ember or rails? Should this default be changed?


#2

Looks like this default is from jQuery.ajax(url, {dataType: 'json'}). What I’m not sure of is what should change. Is this a bug in Rails for returning HTML? Or is it a bug in jQuery for requesting /?

Perhaps either way the Accept header should be set for GET requests, like it is for other requests.


#3

I believe this is a jQuery problem. As a similar solution, I’m using biceps to version my API. So I need to have a specific accept. I’ve solved this with:

$.ajaxSetup({
  accepts: {
    json: 'application/vnd.my_app;ver=1+json'
  }
});