Just looking at adopting v5, and I can't help but notice in the docs/examples, every request involves json_decode on a string. Is this really necessary? Isn't there a better way than having to do this every time?
Thanks, Gav
@gavrichards,
Thanks for reaching out and for the feedback!
There is a better way, we call them helpers. Here is an example of the first one we have begun to build: https://github.com/sendgrid/sendgrid-php/blob/master/lib/helpers/mail/README.md
Future iterations may include library side validation and additional helper functions (right now, we just help you build the payload for the v3 /mail/send).
Please let us know what you would like us to build by creating an issue (or pull request) as we'll be creating a roadmap shortly for the next steps we are planning with this library and will consider all feedback.
Also, you can pass the payload as an array if you prefer, please see the example here: https://github.com/sendgrid/php-http-client Would it help if we also showed the examples using arrays?
With Best Regards,
Elmer
Hi Elmer, thanks for the response! Yes I figured arrays would do the job, I just couldn't understand why you would start with a string of JSON every time, then decode that (presumably to an array) and pass that in, when I think you could just pass in an array which would be neater? I wanted to be sure about that first though. I think what confused me is you're not setting the 2nd parameter of json_decode to true.
@gavrichards,
Apologies for the confusion, I thought having the examples with raw JSON string payloads would be easier to read.
What do you think we could do to avoid that confusion? Perhaps a comment noting that you pass in an array?
I wouldn't like to say, but I am in the process of upgrading our usage of Guzzle from v3 to v6, and also use the AWS PHP SDK heavily, and I've not seen this kind of raw JSON example before, so it confused me. Have you had any feedback from anyone else on this?
I suppose what I'm getting at, is it seems very wasteful to have PHP convert something from one format to another, for every request you make, when that is surely not necessary. If it is the only example you provide though, then I think you can expect people to do that, and it is surely not best practice. I would think a simple associative array of options would be preferred.
Great feedback! We will take this into consideration for the next upcoming iteration.
In thanks for your feedback, please email us at [email protected] with your shirt size :)
BTW, you can track progress on your feedback here: https://github.com/sendgrid/sendgrid-php/issues/254
why would you use json payloads in the php sdk? json_decode to create a php array in the php sdk? it doesn't make sense to me
@adulion,
You don't need to, but this made automating the examples, USAGE.md and unit tests easier for this initial release.
As we iterate on this library, we'll be removing that.
Thanks for the feedback!