librelist archives

« back to archive

Flask Restful - Return String

Flask Restful - Return String

From:
Michael Montero
Date:
2014-04-25 @ 21:43
I want to return a plain XML document from an end point, not have it JSON
encoded.  I'm sure I'm missing something simple but I can't figure out how
to do that.

Help?

Thanks,
Mike

Re: [flask] Flask Restful - Return String

From:
Guillaume Poirier-Morency
Date:
2014-04-25 @ 22:24
What XML library do you use? I think they all provide a function to export
the document as a string.

You only need to return the string representing the document and add the
Content-Type: application/xml to your headers.

In minidom, it looks like

return document.toxml(), 200, {'Content-Type': 'application/xml'}



2014-04-25 17:43 GMT-04:00 Michael Montero <mike@resy.com>:

> I want to return a plain XML document from an end point, not have it JSON
> encoded.  I'm sure I'm missing something simple but I can't figure out how
> to do that.
>
> Help?
>
> Thanks,
> Mike
>



-- 
Guillaume Poirier-Morency <guillaumepoiriermorency@gmail.com>

Développeur Web chez  <http://www.hete.ca>

Re: [flask] Flask Restful - Return String

From:
Michael Montero
Date:
2014-04-25 @ 23:00
Guillaume, thanks for the reply. Just to simplify this, I have a GET end 
point that I just want to return a string. Literally:

return 'hello'

And I don't want it JSON encoded. Can I do that?


> On Apr 25, 2014, at 6:24 PM, Guillaume Poirier-Morency 
<guillaumepoiriermorency@gmail.com> wrote:
> 
> What XML library do you use? I think they all provide a function to 
export the document as a string.
> 
> You only need to return the string representing the document and add the
Content-Type: application/xml to your headers.
> 
> In minidom, it looks like
> 
> return document.toxml(), 200, {'Content-Type': 'application/xml'}
> 
> 
> 2014-04-25 17:43 GMT-04:00 Michael Montero <mike@resy.com>:
>> I want to return a plain XML document from an end point, not have it 
JSON encoded.  I'm sure I'm missing something simple but I can't figure 
out how to do that.
>> 
>> Help?
>> 
>> Thanks,
>> Mike
> 
> 
> 
> -- 
> Guillaume Poirier-Morency <guillaumepoiriermorency@gmail.com>
> 
> Développeur Web chez 

Re: [flask] Flask Restful - Return String

From:
Guillaume Poirier-Morency
Date:
2014-04-25 @ 23:34
Are you asking for something as simple as

@app.route('/endpoint')
def endpoint():
    return 'hello'



2014-04-25 19:00 GMT-04:00 Michael Montero <mike@resy.com>:

> Guillaume, thanks for the reply. Just to simplify this, I have a GET end
> point that I just want to return a string. Literally:
>
> return 'hello'
>
> And I don't want it JSON encoded. Can I do that?
>
>
> On Apr 25, 2014, at 6:24 PM, Guillaume Poirier-Morency <
> guillaumepoiriermorency@gmail.com> wrote:
>
> What XML library do you use? I think they all provide a function to export
> the document as a string.
>
> You only need to return the string representing the document and add the
> Content-Type: application/xml to your headers.
>
> In minidom, it looks like
>
> return document.toxml(), 200, {'Content-Type': 'application/xml'}
>
>
>
> 2014-04-25 17:43 GMT-04:00 Michael Montero <mike@resy.com>:
>
>> I want to return a plain XML document from an end point, not have it JSON
>> encoded.  I'm sure I'm missing something simple but I can't figure out how
>> to do that.
>>
>> Help?
>>
>> Thanks,
>> Mike
>>
>
>
>
> --
> Guillaume Poirier-Morency <guillaumepoiriermorency@gmail.com>
>
> Développeur Web chez  <http://www.hete.ca>
>
>


-- 
Guillaume Poirier-Morency <guillaumepoiriermorency@gmail.com>

Développeur Web chez  <http://www.hete.ca>

Re: [flask] Flask Restful - Return String

From:
Michael Montero
Date:
2014-04-25 @ 23:40
Yes. But the return value using Flask Restful is the string JSON encoded. 
I don't want it encoded.

> On Apr 25, 2014, at 7:34 PM, Guillaume Poirier-Morency 
<guillaumepoiriermorency@gmail.com> wrote:
> 
> Are you asking for something as simple as 
> 
> @app.route('/endpoint')
> def endpoint():
>     return 'hello'
> 
> 
> 2014-04-25 19:00 GMT-04:00 Michael Montero <mike@resy.com>:
>> Guillaume, thanks for the reply. Just to simplify this, I have a GET 
end point that I just want to return a string. Literally:
>> 
>> return 'hello'
>> 
>> And I don't want it JSON encoded. Can I do that?
>> 
>> 
>>> On Apr 25, 2014, at 6:24 PM, Guillaume Poirier-Morency 
<guillaumepoiriermorency@gmail.com> wrote:
>>> 
>>> What XML library do you use? I think they all provide a function to 
export the document as a string.
>>> 
>>> You only need to return the string representing the document and add 
the Content-Type: application/xml to your headers.
>>> 
>>> In minidom, it looks like
>>> 
>>> return document.toxml(), 200, {'Content-Type': 'application/xml'}
>>> 
>>> 
>>> 2014-04-25 17:43 GMT-04:00 Michael Montero <mike@resy.com>:
>>>> I want to return a plain XML document from an end point, not have it 
JSON encoded.  I'm sure I'm missing something simple but I can't figure 
out how to do that.
>>>> 
>>>> Help?
>>>> 
>>>> Thanks,
>>>> Mike
>>> 
>>> 
>>> 
>>> -- 
>>> Guillaume Poirier-Morency <guillaumepoiriermorency@gmail.com>
>>> 
>>> Développeur Web chez 
> 
> 
> 
> -- 
> Guillaume Poirier-Morency <guillaumepoiriermorency@gmail.com>
> 
> Développeur Web chez 

Re: [flask] Flask Restful - Return String

From:
Guillaume Poirier-Morency
Date:
2014-04-27 @ 17:24
This should answer all your questions then!

http://flask-restful.readthedocs.org/en/latest/extending.html#response-formats

You might have to write a callback to export Python object to xml format.
Then you need to set the right Content-Type in your response headers.


2014-04-25 19:40 GMT-04:00 Michael Montero <mike@resy.com>:

> Yes. But the return value using Flask Restful is the string JSON encoded.
> I don't want it encoded.
>
> On Apr 25, 2014, at 7:34 PM, Guillaume Poirier-Morency <
> guillaumepoiriermorency@gmail.com> wrote:
>
> Are you asking for something as simple as
>
> @app.route('/endpoint')
> def endpoint():
>     return 'hello'
>
>
>
> 2014-04-25 19:00 GMT-04:00 Michael Montero <mike@resy.com>:
>
>> Guillaume, thanks for the reply. Just to simplify this, I have a GET end
>> point that I just want to return a string. Literally:
>>
>> return 'hello'
>>
>> And I don't want it JSON encoded. Can I do that?
>>
>>
>> On Apr 25, 2014, at 6:24 PM, Guillaume Poirier-Morency <
>> guillaumepoiriermorency@gmail.com> wrote:
>>
>> What XML library do you use? I think they all provide a function to
>> export the document as a string.
>>
>> You only need to return the string representing the document and add the
>> Content-Type: application/xml to your headers.
>>
>> In minidom, it looks like
>>
>> return document.toxml(), 200, {'Content-Type': 'application/xml'}
>>
>>
>>
>> 2014-04-25 17:43 GMT-04:00 Michael Montero <mike@resy.com>:
>>
>>> I want to return a plain XML document from an end point, not have it
>>> JSON encoded.  I'm sure I'm missing something simple but I can't figure out
>>> how to do that.
>>>
>>> Help?
>>>
>>> Thanks,
>>> Mike
>>>
>>
>>
>>
>> --
>> Guillaume Poirier-Morency <guillaumepoiriermorency@gmail.com>
>>
>> Développeur Web chez  <http://www.hete.ca>
>>
>>
>
>
> --
> Guillaume Poirier-Morency <guillaumepoiriermorency@gmail.com>
>
> Développeur Web chez  <http://www.hete.ca>
>
>


-- 
Guillaume Poirier-Morency <guillaumepoiriermorency@gmail.com>

Développeur Web chez  <http://www.hete.ca>