Please see examples/HttpCallExample/HttpCallExample.ino.
-
include and construct
#include <httpcall.hpp> #include <WiFi.h> #include <ArduinoJson.h> // construct HttpCall httpcall;
-
begin
void setup(void) { // ... WiFi.begin("your ssid", "your wifi password"); httpcall.begin(); // ... }
-
add function
void setup(void) { // ... httpcall.begin(); // id function value is callback argument httpcall.add("test", "test", [](JsonObject j) { Serial.println("http called!"); }); // ... }
-
handle client
void loop(void) { // ... httpcall.handleClient(); // ... }
-
Call function
POSTmethod request tohttp://{your ip}/run.Request header is
{ "id": "test", "function": "test", "value": { // json } }curl command is
curl -X POST "http://{your ip with port}/run" \ -H "Content-Type: application/json" \ -d '{ "id": "test", "function": "test", "value": { "foo": bar" } }'