Closed pengux closed 10 years ago
I had the same issue. Try goweb.API.WriteResponseObject. It takes the context.Context value passed to your handler, the HTTP status, and a value to be converted by the requested codec.
Yes I agree actually - and there is also a transformer for the response object that you can use to unwrap it.
Essentially just return the "d" value.
Sent from my iPhone
On 3 Nov 2013, at 03:46, pengux notifications@github.com wrote:
HI,
maybe I'm missing something but I can't find any obvious way to turn off enveloping of data in responses (http://godoc.org/github.com/stretchr/goweb/responders#pkg-constants)
Data enveloping should not be default (http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api#envelope) but rather let the API creator decide whether to support it or not.
— Reply to this email directly or view it on GitHub.
Would you accept a PR to fix the RespondWithData() so it takes into consideration a ?envelop=true parameter or forcing enveloping by passing a third parameter to it before it envelop the response data?
I’m not sure a parameter is the right place for this - instead, maybe it’s a setting:
goweb.EnvelopeResponse = false
Mat
On 3 Nov 2013, at 08:22, pengux notifications@github.com wrote:
Would you accept a PR to fix the RespondWithData() so it takes into consideration a ?envelop=true parameter before it envelop the response data?
— Reply to this email directly or view it on GitHub.
The GET parameter allows the client to request enveloping the data if required. It's necessary for example JSONP
2013/11/3 Mat Ryer notifications@github.com
I’m not sure a parameter is the right place for this - instead, maybe it’s a setting:
goweb.EnvelopeResponse = false
Mat
On 3 Nov 2013, at 08:22, pengux notifications@github.com wrote:
Would you accept a PR to fix the RespondWithData() so it takes into consideration a ?envelop=true parameter before it envelop the response data?
— Reply to this email directly or view it on GitHub.
— Reply to this email directly or view it on GitHubhttps://github.com/stretchr/goweb/issues/63#issuecomment-27653295 .
Good point - maybe we do both then?
// AlwaysEnvelopeResponse tells Goweb whether to envelope the response
// or not. Default = true (has to be true because of existing code)
goweb.AlwaysEnvelopeResponse = false
AND we'll let clients specify with:
GET /something?envelope=true
Sound good? If so, do you fancy submitting a PR? If so, please give TDD a go, it's pretty cool in Go.
Do you mean to use TDD for the PR? Yes, I can do that. I'll try to submit it during this weekend
MVH
Peter
Chief Technology Officer @ Likipe Digital Website: http://likipe.se Phone: +4633418434
2013/11/5 Mat Ryer notifications@github.com
see https://github.com/stretchr/goweb/wiki/Development-practices
— Reply to this email directly or view it on GitHubhttps://github.com/stretchr/goweb/issues/63#issuecomment-27786316 .
Great - I look forward to it.
Sent from my iPhone
On 6 Nov 2013, at 11:58, pengux notifications@github.com wrote:
Do you mean to use TDD for the PR? Yes, I can do that. I'll try to submit it during this weekend
MVH
Peter
Chief Technology Officer @ Likipe Digital Website: http://likipe.se Phone: +4633418434
2013/11/5 Mat Ryer notifications@github.com
see https://github.com/stretchr/goweb/wiki/Development-practices
— Reply to this email directly or view it on GitHubhttps://github.com/stretchr/goweb/issues/63#issuecomment-27786316 .
— Reply to this email directly or view it on GitHub.
HI,
maybe I'm missing something but I can't find any obvious way to turn off enveloping of data in responses (http://godoc.org/github.com/stretchr/goweb/responders#pkg-constants)
Data enveloping should not be default (http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api#envelope) but rather let the API creator decide whether to support it or not.