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

How to accept std::vector<int> as get or post parameter #50

Closed
fnc12 opened this issue Mar 16, 2017 · 5 comments
Closed

How to accept std::vector<int> as get or post parameter #50

fnc12 opened this issue Mar 16, 2017 · 5 comments

Comments

@fnc12
Copy link

fnc12 commented Mar 16, 2017

I'd like to write a code like this:

PUT / _region * post_parameters(_id = int(),
                                                        _x = int(),
                                                        _y = int(),
                                                        _width = int(),
                                                        _height = int(),
                                                        _comment = std::string(),
                                                        _type = std::string(),
                                                        _near = std::vector<int>()) = [] (auto p) {
                                                   return regionController.put(p.id,
                                                                               p.x,
                                                                               p.y,
                                                                               p.width,
                                                                               p.height,
                                                                               p.comment,
                                                                               p.type,
                                                                               p.near);
                                               }

but I receive a static_assert with

"Target type is neither std::istream`able nor std::wistream`able" 

text

@matt-42
Copy link
Owner

matt-42 commented Mar 16, 2017

I probably forgot to handle this case. I'll fix this very soon.

@matt-42
Copy link
Owner

matt-42 commented Mar 27, 2017

There is accually no standard ways of url-encoding arrays:
https://tools.ietf.org/html/rfc3986#section-3.4
I suggest to start with this syntax:

  • array of integers: aParam[0]=1&aParam[1]=4&aParam[a]=2&aParam[c]=24
  • array of objects: Param[0][name]=xxx&aParam[0][age]=4
  • objects: Param[name]=xxx&aParam[age]=4

Is this what you had in mind ?

@fnc12
Copy link
Author

fnc12 commented Mar 28, 2017

Yes. Precisely: aParam[]=1&aParam[]=4&aParam[]=2&aParam[]=24 and covert it to std::vector<int>. Honestly I expect to have it as a post parameter. But this is a correct syntax for url arrays too

@matt-42
Copy link
Owner

matt-42 commented Mar 29, 2017

I'm about to finish it. It will handle both the array[] syntax (push_back) and the array[N] (set the Nth element).
Nesting will work too (array of object, object of array, array of arrays, etc)

@matt-42
Copy link
Owner

matt-42 commented Mar 31, 2017

It is now in master and works well with the microhttpd backend: e70c4e1

@matt-42 matt-42 closed this as completed Mar 31, 2017
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