marcoschwartz / aREST

A RESTful environment for Arduino
http://aREST.io/
Other
1.2k stars 279 forks source link

Provide access to all passed parameters #217

Closed eykamp closed 6 years ago

eykamp commented 6 years ago

I need to use more complex query strings that is currently permitted (e.g. /setLedParams?color=xyz&bright=123)

This one was a bit of a conundrum; there are several designs which would achieve the goal of providing access to all parameters, while retaining backwards compatibility and allowing people to use the simplified parameter model provided.

Alternatives considered:

  1. passing a parameter to allow different registrations of function to work differently (aREST.function(xxx, true), aREST.function(yyy, false));

  2. two different functions (function() and function2() ?) that provided access to parameters differently; or

  3. (the one I chose) a global setting to change operation of the function feature.

I chose (3) because it seemed cleanest; users will have to parse parameters, and once they have code to do it, they can use it on every use of function().

I am also considering including my code for parsing the function parameters, but it uses STL containers, and thus won't work on all platforms (but does work with ESP8266 and friends). It would be great if, instead of receiving a string, registered functions could receive an already-parsed parameter list. I'm not sure of a good way to do that without STL containers.

The code I'm using is here: https://gist.github.com/eykamp/41179ee60d8f643e2e98f707919e46d5

setLedParamsHandler() is registered with the aREST.function(), and uses the other code to provide a vector of key-value pairs. It could probably be simplified.

marcoschwartz commented 6 years ago

I think the approach you selected is the cleanest indeed - thanks for that! However you are talking about compatibility issues - do you mean that it would break the compatibility of aREST for older boards like the Arduino Uno? Or just for functions with many parameters?

eykamp commented 6 years ago

I meant compatibility with code written to work with earlier versions of aREST. Any of the approaches I discussed should work with any board.

eykamp commented 6 years ago

I did not intend to close/delete this; I thought you had merged it, and was surprised to see my code was gone!

marcoschwartz commented 6 years ago

Hum, strange ... anyway, merging this :)