-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding custom mime type for 'application/vnd.api+json' seems to be required to receive data from clients using JSON API #1027
Comments
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 :). |
@shicholas That seems like a cleaner way to do it, so thank you for that snippet. |
get rid of `ApplicationController#determine_format` hack. More info: rails-api/active_model_serializers#1027 Really dunno why it was working with `determine_format` until `active_model_serializers` were updated to master, but not worth digging this on friday evening :)
get rid of `ApplicationController#determine_format` hack. More info: rails-api/active_model_serializers#1027 Really dunno why it was working with `determine_format` until `active_model_serializers` were updated to master, but not worth digging this on friday evening :)
get rid of `ApplicationController#determine_format` hack. More info: rails-api/active_model_serializers#1027 Really dunno why it was working with `determine_format` until `active_model_serializers` were updated to master, but not worth digging this on friday evening :)
@shicholas Thanks, that was a great help. |
@shicholas Thank you very much! |
@joaomdmoura any news on when we won't have to declare custom MIME type manually for when json_api adapter is selected? |
@matixmatix right now that change would have to be in the Rails JSON Renderer, if I'm not mistaken. or do you mean something like #1027 (comment) |
Was not receiving any data in my update method. Found a solution here: rails-api/active_model_serializers#1027 Need to support the jsonapi mime type application/vnd.api+json for params parser to work properly.
Thank you @rashkov. Mime::Type.unregister :json This solved my issue. |
@boobooninja this solution is technically incorrect, even though it works fine. I basically just removed this pattern from Rails 5. Better would be to register a jsonapi renderer |
@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: /config/initializers/active_model_serializer.rb
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. |
@allthesignals I have a PR open in Rails to return a 415 when a mime type isn't registered. There's a lot of misinformation on the web. Register vnd.api+json as its own media type. AMS provides a way to do this for you. |
It’ll surely turn out that storing a single integer result for each game is too limited, but I’ll address that when it becomes necessary. Thanks to @shicholas for the MIME type pointer here: rails-api/active_model_serializers#1027 (comment)
To enable the mime type Add this to your controller: And use the type
And then in the response, you'll see the header References: |
This solved for me. Thank you! |
@jramiresbrito I'm glad that worked for you. Please be aware we do not recommend that and provide a solution. In the future, when commenting on (years) old resolved threads, it is a good practice to include in your comment what new information you are adding which justifies the thread necromancy. I'm locking this thread now since there's ample references in it to justify it being closed, IMHO. |
Using ember and ember-data with it's built in JSON API support means my client is sending POST/PUT/PATCH requests with
ContentType
set to'application/vnd.api+json'
.By default, even though I've set my adapter in my rails app to
:json_api
, the controller action for create/update doesn't receive any data.After some troubleshooting and googling, I've found out I need to create an initializer to set the rails application to interpret
'application/vnd.api+json'
asjson
: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.
The text was updated successfully, but these errors were encountered: