Pyramid and Cornice XML renderer

551 views Asked by At

Using Pyramid and Cornice, how can I tell Cornice to return XML responses instead of JSON? It seems that by default JSON is used, and this article shows how to add a new text/plain renderer to Cornice. Error responses still contain a JSON body.

How do I switch to XML?

1

There are 1 answers

1
Paul Yin On

As far as I know there are two ways to return XML data:

Render XML with Mako:

<?xml version="1.0" encoding="utf-8"?> 
<information>
</information>

Set the Response Content Type:

request.response.content_type = "text/xml"  
return {'data': 'something'}