-
Notifications
You must be signed in to change notification settings - Fork 6
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
Only parse valid json #28
Only parse valid json #28
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your effort on this. Your changes are a breaking change to the library that I don't think we should implement in this way. There are many servers that send JSON but don't return the correct content-type, and there are also multiple content-types that could contain valid json.
I think a non-breaking implementation would be to add an option to the Requests_response
function, such as parseJson: boolean
. It should be true
by default, but you could also make it a string and support auto
if you're not always sure what response you're going to get.
More than happy to do it that way. I've updated the PR. Although I have to say I really disagree with the approach. Setting a flag to NOT parse json is counter intuitive, and kinda against the design of every requests lib in other languages. Most languages (fetch api in js, requests in python, etc) with have an explicit To justify what I did on my first attempt: I knew there will be concerns for breaking changes, that's why I opted for checking the content-type. In my opinion, any server returning invalid content type is non-compliant and it should be treated as a bug (and still, these are pretty rare anyway) so my attempt was to only parse valid json in most cases. But even on this first attempt, I still think it's better to rip the bandaid off and make the breaking change. The impact is so minimal anyway. Users will have to change code from
to
Which is very minimal effort for a way better experience. |
I completely agree with your assessment. However, we inherited/rescued this project from another developer that wasn't able to maintain it anymore. The ropm published version 0.2.0 was because I didn't want to make it 1.0.0 until I figured out if the ropm version was functional. Then, I completely forgot to bump the version to 1.0.0. This library has been around for ages, and as such, I should go ahead and bump the version to 1.0.0 so that's clear. If you're interested, we could start the process of working towards a v2 release, but I'd like to make sure we clearly thought through additional breaking changes so we could group them together. |
@TwitchBronBron I'm fine with that, we can merge this as is, and figure out v2 as we go. Thanks! |
Great! I just kicked off the v1.0.0 release. Then I'll merge this and cut a 1.1.0 release. Thanks! |
Can you update the readme to include the new option? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. Thank you so much for your work on this!
My pleasure, I also updated changelog! |
roku-requests@1.1.0 has this feature. |
Closes #12