How to respond with JSON directly from a rest call in Grails and bypass the renders

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

How to respond with JSON directly from a rest call in Grails and bypass the renders

scryan
I have a number of REST services that return JSON and the original source is JSON from a Mongo Data Store or it is generated dynamically.   It looks like the only way I can respond back from a Rest call using the Rest Controller is to convert the data from JSON or XML to a Map and let the default renderer render it.   Most of the time the source data is XML or JSON to begin with.   This has incurred huge over head.  Is there a way to:

1. Detect the incoming accept header value
2. Return the true response and bypass the Grails renderers.  That way I can generate either XML or JSON directly and not have to convert it to a MAP. 

I tried just returning the data directly but then it expects to render it as a GSP.  

Is the REST Support for Grails just intended to support CRUD operations or can it also support URL that just request business services?

Thanks

Scott Ryan

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/ffbb1f6d-36b4-4fc0-9991-31ba3a9d5174%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to respond with JSON directly from a rest call in Grails and bypass the renders

dmahapatro-2
This can be done in Grails (latest versions from 2.3). You can get a clear idea about it reading through docs related to respond() which is available to controllers by default.


Hope that helps.


On Fri, Sep 26, 2014 at 6:42 PM, Scott Ryan <[hidden email]> wrote:
I have a number of REST services that return JSON and the original source is JSON from a Mongo Data Store or it is generated dynamically.   It looks like the only way I can respond back from a Rest call using the Rest Controller is to convert the data from JSON or XML to a Map and let the default renderer render it.   Most of the time the source data is XML or JSON to begin with.   This has incurred huge over head.  Is there a way to:

1. Detect the incoming accept header value
2. Return the true response and bypass the Grails renderers.  That way I can generate either XML or JSON directly and not have to convert it to a MAP. 

I tried just returning the data directly but then it expects to render it as a GSP.  

Is the REST Support for Grails just intended to support CRUD operations or can it also support URL that just request business services?

Thanks

Scott Ryan

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/ffbb1f6d-36b4-4fc0-9991-31ba3a9d5174%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Dhiraj..

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/CAAodtxBuV5yopsaM891kG8crDk9eXoOCGtoZA_cuFGzWmPbOVg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to respond with JSON directly from a rest call in Grails and bypass the renders

scryan7371
Not sure if you read my whole post but I am familiar with the documentation and have been using Grails for many years.  The issue is that out of the RestController there does not appear any way to return the payload directly.  If I use respond it tries to convert my data to JSON and assumes it is a map despite the signature being Object. If I use render of couse it tries to render a GSP. If I just return the data is again tries to render a GSP.   I need to be able to return pure JSON from the controller and to return a multi part response with a binarry attachment.  I know I can do this writing my own custom controller however wondering if anyone was able to do this with the default implementation of the RestController.   I have done this with a custom controller but would like to take advantage of the capability in the RestController but return pure JSON as that is what is coming from my Mongo DB and not have to convert it to a map to use the respond function.

Thanks
Scott Ryan

Scott Ryan
President/CTO
Soaring Eagle L.L.C.
Highlands Ranch, Co. 80130
(303) 263-3044
[hidden email]
www.soaringeagleco.com

On Fri, Sep 26, 2014 at 5:34 PM, Dhiraj Mahapatro <[hidden email]> wrote:
This can be done in Grails (latest versions from 2.3). You can get a clear idea about it reading through docs related to respond() which is available to controllers by default.


Hope that helps.


On Fri, Sep 26, 2014 at 6:42 PM, Scott Ryan <[hidden email]> wrote:
I have a number of REST services that return JSON and the original source is JSON from a Mongo Data Store or it is generated dynamically.   It looks like the only way I can respond back from a Rest call using the Rest Controller is to convert the data from JSON or XML to a Map and let the default renderer render it.   Most of the time the source data is XML or JSON to begin with.   This has incurred huge over head.  Is there a way to:

1. Detect the incoming accept header value
2. Return the true response and bypass the Grails renderers.  That way I can generate either XML or JSON directly and not have to convert it to a MAP. 

I tried just returning the data directly but then it expects to render it as a GSP.  

Is the REST Support for Grails just intended to support CRUD operations or can it also support URL that just request business services?

Thanks

Scott Ryan

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/ffbb1f6d-36b4-4fc0-9991-31ba3a9d5174%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Dhiraj..

--
You received this message because you are subscribed to a topic in the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/grails-dev-discuss/Tj3T9ugkkCQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/CAAodtxBuV5yopsaM891kG8crDk9eXoOCGtoZA_cuFGzWmPbOVg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/CAKf31YNaGcbpfPbDfJ%2BJQ%3D76N0tCVJJm_870U%2BrdDGb3pcrk2w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to respond with JSON directly from a rest call in Grails and bypass the renders

dmahapatro-2
Can you provide a simple example (FooController) what you are trying to achieve?

Correct me if I am wrong. 
Are you looking for a simpler approach using RestfulController to produce a multipart HTTP response (a binary attachment (say PDF) ) with a  JSON response body?

Thanks
Dhiraj

On Tue, Sep 30, 2014 at 5:07 PM, Scott Ryan <[hidden email]> wrote:
Not sure if you read my whole post but I am familiar with the documentation and have been using Grails for many years.  The issue is that out of the RestController there does not appear any way to return the payload directly.  If I use respond it tries to convert my data to JSON and assumes it is a map despite the signature being Object. If I use render of couse it tries to render a GSP. If I just return the data is again tries to render a GSP.   I need to be able to return pure JSON from the controller and to return a multi part response with a binarry attachment.  I know I can do this writing my own custom controller however wondering if anyone was able to do this with the default implementation of the RestController.   I have done this with a custom controller but would like to take advantage of the capability in the RestController but return pure JSON as that is what is coming from my Mongo DB and not have to convert it to a map to use the respond function.

Thanks
Scott Ryan

Scott Ryan
President/CTO
Soaring Eagle L.L.C.
Highlands Ranch, Co. 80130
<a href="tel:%28303%29%20263-3044" value="+13032633044" target="_blank">(303) 263-3044
[hidden email]
www.soaringeagleco.com

.

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/CAAodtxBaGRThM2PMhTygrHWmKnR055jzhBb5mgGRRtvXvkXesA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to respond with JSON directly from a rest call in Grails and bypass the renders

Jeff Scott Brown-3
In reply to this post by scryan7371


On September 30, 2014 at 4:07:13 PM, Scott Ryan ([hidden email]) wrote:

> Not sure if you read my whole post but I am familiar with the documentation
> and have been using Grails for many years. The issue is that out of the
> RestController there does not appear any way to return the payload
> directly. If I use respond it tries to convert my data to JSON and assumes
> it is a map despite the signature being Object. If I use render of couse it
> tries to render a GSP. If I just return the data is again tries to render a
> GSP. I need to be able to return pure JSON from the controller and to
> return a multi part response with a binarry attachment. I know I can do
> this writing my own custom controller however wondering if anyone was able
> to do this with the default implementation of the RestController. I have
> done this with a custom controller but would like to take advantage of the
> capability in the RestController but return pure JSON as that is what is
> coming from my Mongo DB and not have to convert it to a map to use the
> respond function.

I am not sure if this is the sort of thing you are looking for or not.  Does something like this help you?…

render(contentType: "application/json") {
    book(title: b.title, author: b.author)
}



JSB

--  
Jeff Scott Brown  
[hidden email]

Find The Cause ~ Find The Cure  
http://www.autismspeaks.org/

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/etPan.542b6df2.327b23c6.544a%40JSB-MBP-August-2012.local.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to respond with JSON directly from a rest call in Grails and bypass the renders

scryan
I will send more details tomorrow but I am looking for something that allows me to send JSON directly.  Like

index(){
def json = '{"name":"Joe","location":"Seattle"}'

respond json
}

but the respond always assumes that json is a map.    The JSON in this case come directly out of a Mongo Database and is returned to the user as JSON.


Scott Ryan

On Sep 30, 2014, at 8:58 PM, Jeff Scott Brown <[hidden email]> wrote:



On September 30, 2014 at 4:07:13 PM, Scott Ryan ([hidden email]) wrote:
Not sure if you read my whole post but I am familiar with the documentation
and have been using Grails for many years. The issue is that out of the
RestController there does not appear any way to return the payload
directly. If I use respond it tries to convert my data to JSON and assumes
it is a map despite the signature being Object. If I use render of couse it
tries to render a GSP. If I just return the data is again tries to render a
GSP. I need to be able to return pure JSON from the controller and to
return a multi part response with a binarry attachment. I know I can do
this writing my own custom controller however wondering if anyone was able
to do this with the default implementation of the RestController. I have
done this with a custom controller but would like to take advantage of the
capability in the RestController but return pure JSON as that is what is
coming from my Mongo DB and not have to convert it to a map to use the
respond function.
 

I am not sure if this is the sort of thing you are looking for or not.  Does something like this help you?…

render(contentType: "application/json") {
    book(title: b.title, author: b.author)
}



JSB

--  
Jeff Scott Brown  
[hidden email]

Find The Cause ~ Find The Cure  
http://www.autismspeaks.org/

--
You received this message because you are subscribed to a topic in the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/grails-dev-discuss/Tj3T9ugkkCQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/etPan.542b6df2.327b23c6.544a%40JSB-MBP-August-2012.local.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/B35CCE0D-5622-4707-BC2B-6D642BD9E089%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to respond with JSON directly from a rest call in Grails and bypass the renders

Jeff Scott Brown-3


On September 30, 2014 at 10:30:49 PM, Scott Ryan ([hidden email]) wrote:

> I will send more details tomorrow but I am looking for something that allows me to send  
> JSON directly. Like
>  
> index(){
> def json = '{"name":"Joe","location":"Seattle"}'
>  
> respond json
> }
>  
> but the respond always assumes that json is a map. The JSON in this case come directly out  
> of a Mongo Database and is returned to the user as JSON.
>  

You can do this…

render json

If json is a String, that will be rendered.



JSB

--  
Jeff Scott Brown  
[hidden email]

Find The Cause ~ Find The Cure  
http://www.autismspeaks.org/

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/etPan.542b7751.643c9869.544a%40JSB-MBP-August-2012.local.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to respond with JSON directly from a rest call in Grails and bypass the renders

scryan7371
If I use your first example it fails trying to use the JSON builder to build JSON from my String. 

If I just render the string it sends the string back in the response however the content type is marked html/text and the cookies are not handled properly.   

I had hoped to use the new Rest capability from Grails as a drop in replacement for my Jersey Grails implementation but it looks like is is a great solution for normal CRUD based grails apps but is a little rough when trying to do deep processing with embedded Paths and non traditional return types.  I will continue to work with it and see if I can get my other use cases to work in the new framework.  It looks great and will continue to improve and is a great solution for a majority of our problems but not really for out more advanced requirements.

thanks for the quick and useful answers

Scott Ryan


On Tue, Sep 30, 2014 at 9:38 PM, Jeff Scott Brown <[hidden email]> wrote:


On September 30, 2014 at 10:30:49 PM, Scott Ryan ([hidden email]) wrote:
> I will send more details tomorrow but I am looking for something that allows me to send
> JSON directly. Like
>
> index(){
> def json = '{"name":"Joe","location":"Seattle"}'
>
> respond json
> }
>
> but the respond always assumes that json is a map. The JSON in this case come directly out
> of a Mongo Database and is returned to the user as JSON.
>


You can do this…

render json

If json is a String, that will be rendered.



JSB

--
Jeff Scott Brown
[hidden email]

Find The Cause ~ Find The Cure
http://www.autismspeaks.org/

--
You received this message because you are subscribed to a topic in the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/grails-dev-discuss/Tj3T9ugkkCQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/etPan.542b7751.643c9869.544a%40JSB-MBP-August-2012.local.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/CAKf31YPF%2BbU9hpMtqxcec56YBsCdDeO%2BCPEMkck2TEWq7LuV4g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to respond with JSON directly from a rest call in Grails and bypass the renders

Gregory Dickson
Scott, you can write to the output stream and set the content type directly. I did this to return a binary image:

def viewImage (){

     def image_record = Image.get( params.id )
     byte[] an_image = image_record.image 
 response.contentType = 'image/png' 
 response.outputStream << an_image


On Wednesday, October 1, 2014 9:16:55 AM UTC-5, Scott Ryan wrote:
If I use your first example it fails trying to use the JSON builder to build JSON from my String. 

If I just render the string it sends the string back in the response however the content type is marked html/text and the cookies are not handled properly.   

I had hoped to use the new Rest capability from Grails as a drop in replacement for my Jersey Grails implementation but it looks like is is a great solution for normal CRUD based grails apps but is a little rough when trying to do deep processing with embedded Paths and non traditional return types.  I will continue to work with it and see if I can get my other use cases to work in the new framework.  It looks great and will continue to improve and is a great solution for a majority of our problems but not really for out more advanced requirements.

thanks for the quick and useful answers

Scott Ryan


On Tue, Sep 30, 2014 at 9:38 PM, Jeff Scott Brown <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="BibaHORJxmcJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">jbr...@...> wrote:


On September 30, 2014 at 10:30:49 PM, Scott Ryan (<a href="javascript:" target="_blank" gdf-obfuscated-mailto="BibaHORJxmcJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">srya...@...) wrote:
> I will send more details tomorrow but I am looking for something that allows me to send
> JSON directly. Like
>
> index(){
> def json = '{"name":"Joe","location":"Seattle"}'
>
> respond json
> }
>
> but the respond always assumes that json is a map. The JSON in this case come directly out
> of a Mongo Database and is returned to the user as JSON.
>


You can do this…

render json

If json is a String, that will be rendered.



JSB

--
Jeff Scott Brown
<a href="javascript:" target="_blank" gdf-obfuscated-mailto="BibaHORJxmcJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">jbr...@...

Find The Cause ~ Find The Cure
<a href="http://www.autismspeaks.org/" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fwww.autismspeaks.org%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNHLOilSQBYB1lzLN6Ms6K6DtQY5DQ';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fwww.autismspeaks.org%2F\46sa\75D\46sntz\0751\46usg\75AFQjCNHLOilSQBYB1lzLN6Ms6K6DtQY5DQ';return true;">http://www.autismspeaks.org/

--
You received this message because you are subscribed to a topic in the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this topic, visit <a href="https://groups.google.com/d/topic/grails-dev-discuss/Tj3T9ugkkCQ/unsubscribe" target="_blank" onmousedown="this.href='https://groups.google.com/d/topic/grails-dev-discuss/Tj3T9ugkkCQ/unsubscribe';return true;" onclick="this.href='https://groups.google.com/d/topic/grails-dev-discuss/Tj3T9ugkkCQ/unsubscribe';return true;">https://groups.google.com/d/topic/grails-dev-discuss/Tj3T9ugkkCQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="BibaHORJxmcJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">grails-dev-discuss+unsubscribe@....
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="BibaHORJxmcJ" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">grails-de...@googlegroups.com.
To view this discussion on the web visit <a href="https://groups.google.com/d/msgid/grails-dev-discuss/etPan.542b7751.643c9869.544a%40JSB-MBP-August-2012.local" target="_blank" onmousedown="this.href='https://groups.google.com/d/msgid/grails-dev-discuss/etPan.542b7751.643c9869.544a%40JSB-MBP-August-2012.local';return true;" onclick="this.href='https://groups.google.com/d/msgid/grails-dev-discuss/etPan.542b7751.643c9869.544a%40JSB-MBP-August-2012.local';return true;">https://groups.google.com/d/msgid/grails-dev-discuss/etPan.542b7751.643c9869.544a%40JSB-MBP-August-2012.local.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" onmousedown="this.href='https://groups.google.com/d/optout';return true;" onclick="this.href='https://groups.google.com/d/optout';return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/4de64b60-0160-43f2-b7b0-966917498fae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to respond with JSON directly from a rest call in Grails and bypass the renders

Jeff Scott Brown-3
In reply to this post by scryan7371


On October 1, 2014 at 9:16:55 AM, Scott Ryan ([hidden email]) wrote:
> If I use your first example it fails trying to use the JSON builder to
> build JSON from my String.
>  
> If I just render the string it sends the string back in the response
> however the content type is marked html/text and the cookies are not
> handled properly.

If you want to specify the content type you can…

render text: someStringThatContainsJSON, contentType: “application/json”



JSB
--  
Jeff Scott Brown  
[hidden email]

Find The Cause ~ Find The Cure  
http://www.autismspeaks.org/

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/etPan.542c181b.327b23c6.5b80%40JSB-MBP-August-2012.local.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to respond with JSON directly from a rest call in Grails and bypass the renders

dmahapatro-2
You beat me to it, Jeff.

@Scott - You can also specify the status code in case you are handling an error json response

render text: errorjsonstring, contentType: 'application/json', status: 400

Sorry its thumb typed, google groups is blocked at my work place. this will be an immediate request right now to unblock.

Thanks
Dhiraj Mahapatro

> On Oct 1, 2014, at 11:04 AM, Jeff Scott Brown <[hidden email]> wrote:
>
>
>
>> On October 1, 2014 at 9:16:55 AM, Scott Ryan ([hidden email]) wrote:
>> If I use your first example it fails trying to use the JSON builder to
>> build JSON from my String.
>>
>> If I just render the string it sends the string back in the response
>> however the content type is marked html/text and the cookies are not
>> handled properly.
>
> If you want to specify the content type you can…
>
> render text: someStringThatContainsJSON, contentType: “application/json”
>
>
>
> JSB
> --  
> Jeff Scott Brown  
> [hidden email]
>
> Find The Cause ~ Find The Cure  
> http://www.autismspeaks.org/
>
> --
> You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> To post to this group, send email to [hidden email].
> To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/etPan.542c181b.327b23c6.5b80%40JSB-MBP-August-2012.local.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/32C479AF-F15E-46C9-A484-7A340259B4FC%40gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to respond with JSON directly from a rest call in Grails and bypass the renders

Paco Zarate
Great tips!

Thank you guys, I will be using them on my project too, I have a similar use case.


On Wed, Oct 1, 2014 at 9:16 AM, Dhiraj Mahapatro <[hidden email]> wrote:
You beat me to it, Jeff.

@Scott - You can also specify the status code in case you are handling an error json response

render text: errorjsonstring, contentType: 'application/json', status: 400

Sorry its thumb typed, google groups is blocked at my work place. this will be an immediate request right now to unblock.

Thanks
Dhiraj Mahapatro

> On Oct 1, 2014, at 11:04 AM, Jeff Scott Brown <[hidden email]> wrote:
>
>
>
>> On October 1, 2014 at 9:16:55 AM, Scott Ryan ([hidden email]) wrote:
>> If I use your first example it fails trying to use the JSON builder to
>> build JSON from my String.
>>
>> If I just render the string it sends the string back in the response
>> however the content type is marked html/text and the cookies are not
>> handled properly.
>
> If you want to specify the content type you can…
>
> render text: someStringThatContainsJSON, contentType: “application/json”
>
>
>
> JSB
> --
> Jeff Scott Brown
> [hidden email]
>
> Find The Cause ~ Find The Cure
> http://www.autismspeaks.org/
>
> --
> You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> To post to this group, send email to [hidden email].
> To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/etPan.542c181b.327b23c6.5b80%40JSB-MBP-August-2012.local.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/32C479AF-F15E-46C9-A484-7A340259B4FC%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/CALsYiCiyXjNUFxPC-%3DCgYwOm%2BDu2vyju8ry9PJkA4AaKpedDTw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.