Echo: Add support for yaml encoding response / decoding request

Created on 9 Jan 2019  ·  12Comments  ·  Source: labstack/echo

Hello,

I didn't see anything relative to an automatic binding when someone a POST request with a YAML body. Same thing when the server send the response with YAML format.

Apart from the stream, we could have the same method that the one for JSON, like that

func (c *context) YAML(code int, i interface{}) (err error) {
}

func (c *context) YAMLPretty(code int, i interface{}, indent string) (err error) {
}

func (c *context) YAMLBlob(code int, b []byte) (err error) {
}

Are you interesting by this idea ? And by the implementation also ?

Thanks for your amazing work :)

enhancement suggestion wontfix

Most helpful comment

I think we should be cognizant about adding new functions to the context. To me, in last 4 years this is the first time someone is concerned about yaml response. I would recommend to extend context and add your own functions - https://echo.labstack.com/guide/context

All 12 comments

Any update on this ? Just tell me if it's something that you like or not :). Thanks by advance for your response

Thank you @Nexucis for the suggestion. We'll consider it and get back to you.

Hello, I did a PR here https://github.com/labstack/echo/pull/1273 to implement YAML at Bind() :smile: .

Thank you for your contribution :) You're doing very well for your 1st contribution! :)

This feature looks small and innocent :) but I'm more worried about the trend it sets for future development... What if tomorrow someone comes with adding support for TOML (or X, Y, Z...)? Do we add them all to the core of the Echo? Also, how common is for APIs to consume YAML? Does anyone know? I have worked with YAML, just not as an API request format. Last but not least, is there even an agreed upon MIME type for YAML? :-) I see a lot of proposals and not a lot of consensus...

@vishr @im-kulikov (and anyone else really) what are you thoughts on this?

I for one think that using the custom binder is preferable than extending Bind() for less used formats. But that's just me. Not trying to be picky or anything, I just value the "minimalism" of Echo very much. But maybe others value "batteries included" more, so let's discuss.

I think we should be cognizant about adding new functions to the context. To me, in last 4 years this is the first time someone is concerned about yaml response. I would recommend to extend context and add your own functions - https://echo.labstack.com/guide/context

I’m agree with @vishr..

I’m using YAML because in JSON format you have to escape and you can’t use line break.

@alexaandru You right about the fact that echo has to be lightweight service

Thanks @vishr, I will check it

On my side, I think YAML is becoming as standard as JSON, specially with the arrival of Kubernetes, Prometheus, and other cloud technology that proposed both format in their API.

Thanks @Nexucis - that's interesting. Still, from proposal to implementation many things can happen :-) Does K8s use YAML today? All I see in it's docs are JSON fragments: https://kubernetes.io/docs/reference/using-api/api-concepts/

Also, just because we say no today, it doesn't mean we'll say no in the future as well. If state of the industry changes, and more people start asking about this, we will reconsider it of course.

Yeah it's not really easy to know what exactly Kubernetes support, specially when they didn't say it in their API documentation :

To know it, I pass by the Openshift documentation which describe the different format produces

Thanks @Nexucis so K8s does indeed talk YAML already. Interesting...

If this becomes more mainstream (talking YAML, that is), we'll revisit it. At this time an alternate solution was suggested already, so closing this one. Sorry that your 1st PR ended up being rejected, hope you agree it's the best way to go for Echo, at this time. Thank you & have a great day!

Thanks guys 👍

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wangxianzhuo picture wangxianzhuo  ·  4Comments

absinsekt picture absinsekt  ·  4Comments

younisshah picture younisshah  ·  4Comments

linux-support picture linux-support  ·  3Comments

dre1080 picture dre1080  ·  4Comments