Closed bystro closed 6 years ago
Ok. Pull request is ready for review.
Sorry to take time about this PR but I still not convinced we could do that.
How do you inform your backend that body is json as the content-type is multipart ? ping @shouze
The request is not being sent with "application/json" header!
Even if you mannualy set header to "application/json" https://github.com/ubirak/rest-api-behat-extension/pull/93/files#diff-7e75094618ac1c011c28df106748e912R46 the request still is being sent as '"multipart/form-data" https://github.com/ubirak/rest-api-behat-extension/pull/93/files#diff-7e75094618ac1c011c28df106748e912R64
Request behaves as request sent from HTML form.
Yes I got it and it is exactly my problem ;) You send a file and a json body. You inform your backend about the file but not the json body. So I still wondering how it could work in a real world app
Every json body attribute is being transformed into multipart/form-data https://github.com/ubirak/rest-api-behat-extension/pull/93/files#diff-9d1a35b8dac9c540c2aedf7c51d8e7e7R210
Json body is being sent as common HTML form fields with names and values
See 'post_fields_count' equals 3 because fields are being sent as HTML form and fields are placed in $_POST superglobal. https://github.com/ubirak/rest-api-behat-extension/pull/93/files#diff-7e75094618ac1c011c28df106748e912R62
In my ZendFramework api apps it works out of the box(natively) because it handles this way https://github.com/zendframework/zend-mvc/blob/master/src/Controller/AbstractRestfulController.php#L469
If request is not with 'application/json' headers, then it gets body from $_POST.
Ok, thanks for the explanation I get your point.
So we clearly need to remove this magic stuff where we switch from json to array in fact.
I guess we had in a previous version the possibility to pass a body as an array (it would explain the outdated phpdoc you mentioned). We just need to get back this behavior.
I have some time this afternoon, I will have a deeper look to merge this PR without magic
"So we clearly need to remove this magic stuff where we switch from json to array in fact." What do you mean?
We inject json in PyString and transform it in array without let people know
Oh, OK. Will you correct this ?
Yes I'm on it !
Closed in favor of #94
I have tested the code with ZendFramework's AbstractRestfulControlle and tests passed https://github.com/zendframework/zend-mvc/blob/master/src/Controller/AbstractRestfulController.php