proofgeist / generator

Generator - Store, explore, share and create FileMaker Code
MIT License
35 stars 8 forks source link

Handle array params #21

Closed bnzo closed 7 years ago

bnzo commented 7 years ago

Issue with an API based on "application/x-www-form-urlencoded" format: http://our.api.com/Product?id[]=101404&id[]=7267261

This is a "standard" call with params but sometimes we can face APIs with different ways to handle params like: http://our.api.com/Product?id=["101404","7267261"] http://our.api.com/Product?id=101404,7267261

toddgeist commented 7 years ago

Is this mostly about adding support for "application/x-www-form-urlencoded", which is pretty lame right now. Or are you using the "Params" and expecting those to POST?

bnzo commented 7 years ago

Hi Todd,

This is a GET request to retrieve products info based on one or many id_product. I do a manual insert from URL request for now but I guess we should handle array params depending on content-type request later. Not a pain for now, I don't need this very often. That was more to mention different kind of array params in APIs. Adding a param type "array" could be interesting...

screen shot 2017-06-20 at 15 19 42
toddgeist commented 7 years ago

Ah ok, That confused me. A GET Request doesn't use "application/x-www-form-urlencoded" There is no ContentType when you do a GET as there is no Content.

The example you are using should work. The Query Params you have added should be URL encoded and should get added to the URL. If that is not the case, then please add a little more detail with the error you are getting or a test case we can use.

Thanks

bnzo commented 7 years ago

Sorry for the confusion. I wanted to mention the API uses "application/x-www-form-urlencoded"as a "standard" for url array params in GET requests. Anyway this topic is more about how to handle array params in json. Have a look at the following screenshot, you will understand.

Regards

screen shot 2017-06-20 at 16 16 55
toddgeist commented 7 years ago

Ah I see. So the problem is that anything that uses the same param more than once only gets the last repeat when it is converted to JSON and back.

Frankly not sure what to about that.

bnzo commented 7 years ago

Not a big deal, I can handle array params manually, generator is already useful for all the rest!