Closed OidaTiftla closed 6 years ago
I also updated this branch :)
Merged this one as well, thanks again for your contribution! As usual I'll spend some time testing it with all the boards to make sure it all works smoothly.
One thing is that I will have to remove the examples with aquariumController from the examples, as it is too specific and also the code in the api extension is too long for the examples. However, I invite you to create a new example (for example esp8266_api_extension.ino) to show people how to use this new function :)
Unfortunately I had to revert this and also the previous commit as it created issues with accessing variables via the cloud server. Please check that, and I'd be happy to merge your changes again once this is fixed :)
Okay, no problem, it was just for the sake of completeness. I'll copy it to a new example file.
I'll have a look at the cloud server problem.
Hi, if you don't like the changes, don't mind and simply close this pull request 😄
This pull request builds upon pull request #238.
The possibility is added to extend the api by your own subcommands and customized responses. The unit tests are also extended, and tested as far as I could do with my setup (Ethernet Shield on Arduino). With my setup, all test run through now 😅 The examples section is also updated with the new snippets.
I hope you feel comfortable with the changes. If anything is not working, or you have other ideas, I'm looking forward to hearing from you.
The backwards compatibility of the API of the library is kept and the API can be used in the same way as before:
To explain the new functionality, I copied the updated README.md section below:
API-Extensions
You can also define your api extensions in your sketch that can be called using the REST API. To access an user-defined api-extension defined in your sketch, you have to declare it first, and then call it from with a REST call. Note that all api-extension functions need to have the following signature
void api_extension(aREST *arest, const String& name, const String& request_url)
. For example, if your aREST instance is called "rest" and the function "aquariumController":rest.api_extension("aquarium",aquariumController);
declares the api extension in the Arduino sketch/aquarium/water_limit/lower/set/65
executes the api-extension function and passes the value"/aquarium/water_limit/lower/set/65"
as the third parameter (request_url
) into the api-extension function