Skip to content

Commit 1a9f647

Browse files
committed
Updating example
1 parent 5dbf4f7 commit 1a9f647

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

examples/HTTPMethods/HTTPMethods.ino

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@
2929

3030
static AsyncWebServer server(80);
3131

32+
// https://github.com/ESP32Async/ESPAsyncWebServer/issues/404
33+
static void handlePostTest(AsyncWebServerRequest *req, JsonVariant &json) {
34+
AsyncWebServerResponse *response;
35+
if (req->method() == WebRequestMethod::HTTP_POST) {
36+
response = req->beginResponse(200, "application/json", "{\"msg\": \"OK\"}");
37+
} else {
38+
response = req->beginResponse(501, "application/json", "{\"msg\": \"Not Implemented\"}");
39+
}
40+
req->send(response);
41+
}
42+
3243
void setup() {
3344
Serial.begin(115200);
3445

@@ -48,6 +59,11 @@ void setup() {
4859
request->send(200, "text/plain", "Hello");
4960
});
5061

62+
// curl -v http://192.168.4.1/test => Not Implemented
63+
// curl -v -X POST -H 'Content-Type: application/json' -d '{"name":"You"}' http://192.168.4.1/test => OK
64+
AsyncCallbackJsonWebHandler *testHandler = new AsyncCallbackJsonWebHandler("/test", handlePostTest);
65+
server.addHandler(testHandler);
66+
5167
server.begin();
5268
}
5369

0 commit comments

Comments
 (0)