Skip to content

Why do we have to create a separate handler for json post? #300

@zekageri

Description

@zekageri

Platform

ESP32

IDE / Tooling

Arduino (IDE/CLI)

What happened?

I have tried to use this syntax

server.on("/testJsonPost", HTTP_POST, [](AsyncWebServerRequest *request, JsonVariant &json) { // handle the json request... });

Why do I have to create a separate handler for it?

This is ridiculusly long.

auto *testPostHandler= new AsyncCallbackJsonWebHandler("/testJsonPost", [](AsyncWebServerRequest *request, JsonVariant &json) { // handle the json request... }); testPostHandler->setMethod(HTTP_POST); server.addHandler(testPostHandler);

Stack Trace

no instance of overloaded function "AsyncWebServer::on" matches the argument listC/C++(304)
network-routes.cpp(24, 12): argument types are: (const char *, WebRequestMethod, lambda [](AsyncWebServerRequest *request, ArduinoJson::V742PB22::JsonVariant &json)->void)
network-routes.cpp(24, 12): object type is: AsyncWebServer

Minimal Reproductible Example (MRE)

server.on("/testJsonPost", HTTP_POST, [](AsyncWebServerRequest *request, JsonVariant &json) { // handle the json request... });

I confirm that:

  • I have read the documentation.
  • I have searched for similar discussions.
  • I have searched for similar issues.
  • I have looked at the examples.
  • I have upgraded to the lasted version of ESPAsyncWebServer (and AsyncTCP for ESP32).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions