matt-42 / silicon

A high performance, middleware oriented C++14 http web framework please use matt-42/lithium instead
http://siliconframework.org
MIT License
1.72k stars 138 forks source link

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

Closed fnc12 closed 7 years ago

fnc12 commented 7 years ago

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 commented 7 years ago

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

matt-42 commented 7 years ago

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:

Is this what you had in mind ?

fnc12 commented 7 years ago

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 commented 7 years ago

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 commented 7 years ago

It is now in master and works well with the microhttpd backend: https://github.com/matt-42/silicon/commit/e70c4e19881cc591516eb358bb400cd950b2e339