Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
Adding custom mime type for 'application/vnd.api+json' seems to be required to receive data from clients using JSON API #1027
Using ember and ember-data with it's built in JSON API support means my client is sending POST/PUT/PATCH requests with
By default, even though I've set my adapter in my rails app to
After some troubleshooting and googling, I've found out I need to create an initializer to set the rails application to interpret
ActionDispatch::ParamsParser::DEFAULT_PARSERS[Mime::Type.lookup('application/vnd.api+json')]=lambda do |body| JSON.parse(body) end
Once this was added, I'm receiving the data as expected.
The issue here is, i'm not sure if this is what I'm supposed to be doing.
If it's one of the first 3, I'm thinking it should be documented in some way.
Hey @begedin, thank you for the issue:
Probably, you might not even need to set the adapter depending on how we decide to do this.
Not sure, we haven't started to implement it so it's a new problema for us as well, but we are already working on deserialization, what means we will face this problem soon.
As I said, I'm not sure, we will face the same problem on the deserialization implementation the next days, so might find another way but you're ahead of us for now
No, we don't support it yet.
I'll close this one for now but will keep the dicussion opened, mostly because I want to give updates base on the implementation that we will work on! Also, @begedin, let us know in case you have any problem with this, I might open the issue again and we will definitely help you
hey @begedin I'm using rails with AMS
api_mime_types = %W( application/vnd.api+json text/x-json application/json ) Mime::Type.unregister :json Mime::Type.register 'application/json', :json, api_mime_types
and everything seems to be working fine :).
Thank you @rashkov.
This solved my issue.
@bf4 could you elaborate ? Could you give a dirty but correct solution ?
I use 0.10.0.rc5 with JSONAPI and I had the same issue. It can be VERY furstrating I thing I am lucky that I found this issue in the first 30 mins. What it needs to be done so that users don't have this issue ?
ActiveSupport.on_load :action_controller do
Sorry, on phone
If you can make a pr summarizing what brought you here and what the solution is, that would be great.
Maybe see http://www.benjaminfleischer.com/journey-of-a-media-type-in-rails-part-1 re content negotiation
B mobile phone
Fix two problematic bits of code that will be deprecated or broken in Rails 5. Found in the Rails 5 MR: !5555 These are safe to use in Rails 4.2.7 as well as Rails 5.0.0, so I figured I'd backport them for the sake of making that merge request smaller. The explanation for the mime_types.rb code is here: rails-api/active_model_serializers#1027 (comment) See merge request !6214
I am using AMS 0.10.2 with Ember 2.7 and did not need to register a mime type for everything to work. I simply added the AMS gem and configured it as recommended:
However, the Header being sent from Rails is
My understanding is that if you want the api to be spec-compliant, the server should respond with the latter mime-type.
In order to achieve that, then you need to register the correct mime-type, even though it seems Ember and the API work without doing so.
Is there some mismatch going on here or am I just not groking something here?
@rmcsharry are you using
You shouldn't need to register the mime type yourself anymore, if you are using
If that helps, I suggest we close this issue (as much of the discussion is dated and now misleading) and maybe make that section of the documentation more obvious.
I think I'm having this exact issue. I'm using AMS 0.10.4 with Rails 4.2.
Is there something obvious I'm missing? Maybe there's another gem that's interfering. I did include the special initializer mentioned in the ember README.