Skip to content

Commit a251ca5

Browse files
committed
Merge remote-tracking branch 'origin/main' into requestmethod-typing
2 parents 2ff30c8 + c515c2a commit a251ca5

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

examples/HTTPMethods/HTTPMethods.ino

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@
2727

2828
static AsyncWebServer server(80);
2929

30+
#if ASYNC_JSON_SUPPORT == 1
31+
// https://github.com/ESP32Async/ESPAsyncWebServer/issues/404
32+
static void handlePostTest(AsyncWebServerRequest *req, JsonVariant &json) {
33+
AsyncWebServerResponse *response;
34+
if (req->method() == WebRequestMethod::HTTP_POST) {
35+
response = req->beginResponse(200, "application/json", "{\"msg\": \"OK\"}");
36+
} else {
37+
response = req->beginResponse(501, "application/json", "{\"msg\": \"Not Implemented\"}");
38+
}
39+
req->send(response);
40+
}
41+
#endif
42+
3043
// user defined functions that turns out to have similar signatures to the ones in global header
3144
int stringToMethod(const String &) {
3245
return 0;
@@ -71,6 +84,13 @@ void setup() {
7184
request->send(200, "text/plain", "Hello");
7285
});
7386

87+
#if ASYNC_JSON_SUPPORT == 1
88+
// curl -v http://192.168.4.1/test => Not Implemented
89+
// curl -v -X POST -H 'Content-Type: application/json' -d '{"name":"You"}' http://192.168.4.1/test => OK
90+
AsyncCallbackJsonWebHandler *testHandler = new AsyncCallbackJsonWebHandler("/test", handlePostTest);
91+
server.addHandler(testHandler);
92+
#endif
93+
7494
// curl -v -X HEAD http://192.168.4.1/custom => answers
7595
// curl -v -X OPTIONS http://192.168.4.1/custom => answers
7696
// curl -v -X POST http://192.168.4.1/custom => no answer

0 commit comments

Comments
 (0)