Skip to content

Adding custom mime type for 'application/vnd.api+json' seems to be required to receive data from clients using JSON API #1027

@begedin

Description

@begedin

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' as json:

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.

  1. Will AMS at some point do this, or something similar internally?
  2. Should I do it this way?
  3. Should I do it some other, more proper way?
  4. Did I miss something altogether? Is it well documented already and I actually just didn't set some property somewhere?

If it's one of the first 3, I'm thinking it should be documented in some way.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions