Returning Content-Type XML from calling a function

Hey all,

I’m trying to create a function that acts as an RSS feed. I’ve got it working locally (using netlify-lambda), but when I deploy it to Netlify and try to access it, I see the following error in my logs:

error decoding lambda response: json: cannot unmarshal number into Go value of type string

This makes me wonder if it is even possible to respond with anything other than JSON?

I just tested the following simple function. Looks like you can return xml.

const getResponse = myxml => ({
  statusCode: 200,
  headers: {
    'Content-Type': 'text/xml',
  },
  body: myxml,
});

exports.handler = function(event, context, callback) {
  const response = getResponse(`<?xml version="1.0" encoding="UTF-8"?>
  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
    <url>
        <loc>http://www.example.com/</loc>
        <lastmod>2005-01-01</lastmod>
        <changefreq>monthly</changefreq>
        <priority>0.8</priority>
    </url>
  </urlset>`)
  callback(null, response)
}

image

1 Like

Thanks so much! I had the Content-Type set to application/rss+xml; charset=utf-8, which did not work. I’ve changed it to text/xml and now it does!

1 Like

Glad it worked! You can mark it as solved if you want. Will help Netlify support to not spend too much time on it. :grin:

1 Like