Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for yaml encoding response / decoding request #1252

Closed
Nexucis opened this issue Jan 9, 2019 · 12 comments
Closed

Add support for yaml encoding response / decoding request #1252

Nexucis opened this issue Jan 9, 2019 · 12 comments

Comments

@Nexucis
Copy link

Nexucis commented Jan 9, 2019

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 :)

@Nexucis
Copy link
Author

Nexucis commented Jan 18, 2019

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

@alexaandru
Copy link
Contributor

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

@thecampagnards
Copy link

Hello, I did a PR here #1273 to implement YAML at Bind() 😄 .

@alexaandru
Copy link
Contributor

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.

@vishr
Copy link
Member

vishr commented Jan 31, 2019

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

@im-kulikov
Copy link
Contributor

I’m agree with @vishr..

@thecampagnards
Copy link

thecampagnards commented Jan 31, 2019

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

@Nexucis
Copy link
Author

Nexucis commented Feb 1, 2019

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.

@alexaandru
Copy link
Contributor

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.

@Nexucis
Copy link
Author

Nexucis commented Feb 1, 2019

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

@alexaandru alexaandru self-assigned this Feb 2, 2019
@alexaandru
Copy link
Contributor

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!

@vishr
Copy link
Member

vishr commented Feb 4, 2019

Thanks guys 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants