[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().
Create an iron-ajax for a resource expecting content in the request (typically a PUT/POST).
Set the body to be a javascript object.
Set the contentType property, or the Content-Type header, to application/vnd.foo.bar-v1+json.
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.
Description
Specifying a
Content-Type
header ofapplication/vnd.foo.bar-v1+json
and setting thebody
of aniron-ajax
to an object is not supported.As per https://tools.ietf.org/html/rfc6839 section 3:
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
iron-ajax
for a resource expecting content in the request (typically a PUT/POST).body
to be a javascript object.contentType
property, or theContent-Type
header, toapplication/vnd.foo.bar-v1+json
.Source code reference
The
_encodeBodyObject()
ofiron-request.html
contains aswitch/case
that specifically checks forapplication/json
andapplication/x-www-form-urlencoded
. I suppose an.endsWith("+json")
is a reasonable approach, but[object Object]
is really never a good fallback.