Skip to content
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

Support for +json media type suffix #294

Open
mmartensson opened this issue Sep 12, 2017 · 1 comment
Open

Support for +json media type suffix #294

mmartensson opened this issue Sep 12, 2017 · 1 comment

Comments

@mmartensson
Copy link

Description

Specifying a Content-Type header of application/vnd.foo.bar-v1+json and setting the body of an iron-ajax to an object is not supported.

As per https://tools.ietf.org/html/rfc6839 section 3:

[RFC4627] defines the "application/json" media type. The suffix
"+json" MAY be used with any media type whose representation follows
that established for "application/json".

Reasons for using a +json suffixed media type include versioning of REST calls and resources that can handle variations of request payloads.

Expected outcome

The data posted to the server is the object having passed through JSON.stringify().

Actual outcome

The data posted to the server is [object Object].

Live Demo

https://jsbin.com/necokalogu/edit?html,output

Steps to reproduce

  1. Create an iron-ajax for a resource expecting content in the request (typically a PUT/POST).
  2. Set the body to be a javascript object.
  3. Set the contentType property, or the Content-Type header, to application/vnd.foo.bar-v1+json.
  4. Send the request.

Source code reference

The _encodeBodyObject() of iron-request.html contains a switch/case that specifically checks for application/json and application/x-www-form-urlencoded. I suppose an .endsWith("+json") is a reasonable approach, but [object Object] is really never a good fallback.

@phidias51
Copy link

I tried using application/hal+json for a restful request but the content type was still set to application/json in the GET request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants