[GetConnect] Make FormData as the default acceptable parameter. #1525
pratamatama
started this conversation in
Ideas
Replies: 1 comment
-
FormData should NOT be the default, since mobile apps, in most cases, consume APIs which send and receive JSON (map) data. JSON is the de facto standard for APIs. Since you're working with Laravel. Imagine FormData as being an html-form. It by default has no boolean values, therefore "1". And the Laravel validator can validate boolean if you send it as JSON. So, your (serverside) decision of accepting multipart formdata, instead of JSON is not necessarily wrong, but it's not "how it's done nowadays". I was recently working on a project, where I had to consume 3 APIs, one of which accepted FormData, while all others accepted JSON. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently there is 2 approach to send data from the client to the server through GetConnect. One with
FormData
and one with justMap
. Why not just unify the usage like makingFormData
as the default requirement as the parameter? Andconvert them to JSON internallyjust let them pass asMap
if noMultipartFile
provided.These "separation" of type are confusing for people that want to get started. And currently,
FormData
also create a problem forbool
; which was converted into aString
("true"
, and"false"
), which are unacceptable by some serverside validator like Laravel.Take this snippet as example:
There, we want to send data which might contain a
MultipartFile
and also contain abool
. And guess, because we are using Laravel and it doesn't allow string representation of boolean, the validation will fail. And sinceMap
produce this error, we cannot use it.The only way to do this is to manually cast the boolean value into a string of
"1"
or"0"
, on every single part of the code that needed the same data structure to be sent. Not a big deal, but it's repetitive. Or make a custom middleware/validator on serverside that could possibly create a security issue if not taken seriously. Iftrue
andfalse
are acceptable, and won't produce security issue, why not just allow it to be as it is instead of converting it to a string?It also create inconsistency between classes, which some of their method accepts
Map
and some acceptsFormData
. Wouldn't it be nice if everything are set toFormData
and we could just get rid of that "Am I doing it right?" feeling when you just getting started with GetX?What do you think?
Beta Was this translation helpful? Give feedback.
All reactions