I am using the Loopback Connector REST (1.9.0) and have a remote method that returns XML:
Foo.remoteMethod
(
"getXml",
{
accepts: [
{arg: 'id', type: 'string', required: true }
],
http: {path: '/:id/content', "verb": 'get'},
returns: {"type": "string", root:true},
rest: {"after": setContentType("text/xml") }
}
)
The response always returns an escaped JSON string:
"<foo xmlns=\"bar\"/>"
instead of
<foo xmlns="bar"/>
Note that the response does have the content-type set to text/xml.
If I set my Accept: header to "text/xml", I always get "Not Acceptable" as a response.
If I set
"rest": {
"normalizeHttpPath": false,
"xml": true
}
In config.json, then I get a 500 error:
SyntaxError: Unexpected token <
I think that the "xml: true" property is simply causing a response parser to try to convert JSON into XML.
How can I get Loopback to return the XML in the response without parsing it? Is the problem that I am setting the return type to "string"? If so, what it the type that Loopback would recognize as XML?