Skip to content
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

Add support array index #132

Open
heckad opened this issue Jan 8, 2021 · 5 comments
Open

Add support array index #132

heckad opened this issue Jan 8, 2021 · 5 comments

Comments

@heckad
Copy link

heckad commented Jan 8, 2021

Propose to add support array as arg. For example

print(furl('http://example.org', args={'f': [1, 2, 3]}))

should return

http://example.org?f[0]=1&f[1]=2&f[2]=3
@gruns
Copy link
Owner

gruns commented Jan 8, 2021

Is f[0]=1&f[1]=2&f[2]=3 a commonly used query notation to represent a dictionary of values, eg {'f': [1, 2, 3]}? I, personally, have never seen that URL query style used before.

Do you have any examples of that format, var[key]=value&var[key]=value&... in the wild?

Thank you!

@heckad
Copy link
Author

heckad commented Jan 8, 2021

https://www.cian.ru/cat.php?deal_type=sale&engine_version=2&offer_type=flat&region=1&room0=1&rooms_count[0]=1&rooms_count[1]=2&rooms_count[2]=3

@gruns
Copy link
Owner

gruns commented Jan 8, 2021

interesting! thank you for the link!

have you seen this query pattern on other sites beyond cian.ru, too?

the first result of furl('http://example.org', args={'f': [1, 2, 3]})
that comes to my mind isn't dictionary-like keys, but duplicate,
repeated keys. this:

http://example.org?f=1&f=2&f=3

I've seen the above duplicate, repeated keys pattern in the wild
multiple times before. it's less surprising to me than
?f[0]=1&f[1]=2&f[2]=3 is

the args= value that produces ?f[0]=1&f[1]=2&f[2]=3 that comes to my
mind first is args={'f': {0: 1, 1: 2, 2: 3]}

what do you think about args={'f': {0: 1, 1: 2, 2: 3]} turning into
?f[0]=1&f[1]=2&f[2]=3. would this suffice for your use case?

@heckad
Copy link
Author

heckad commented Jan 9, 2021

Maybe add option for serialize array? You can do it by 3 possible methods

  1. http://example.org?f=1,2,3
  2. http://example.org?f=1&f=2&f=3
  3. http://example.org?f[0]=1&f[1]=2&f[2]=3

This can be achieved by adding list wrappers. For example: A, B, C (where A,B,C some talking names) and use it as furl('http://example.org', args={'f': A([1, 2, 3])}) or add default value to furl kwarg.

P. S. I'm not good enough at English. If you correct me in the syntax I would be grateful.

Thank you

@heckad
Copy link
Author

heckad commented Jan 13, 2021

@gruns, what you say?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants