Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

How to make a rest endpoint / recive json #594

@thbl

Description

@thbl

Hi

I'm new to esp can some one give an example, on how to make a rest endpoint and parse json.
i tried running the sample code

#include "AsyncJson.h"
#include "ArduinoJson.h"

AsyncCallbackJsonWebHandler* handler = new AsyncCallbackJsonWebHandler("/rest/endpoint", [](AsyncWebServerRequest *request, JsonVariant &json) {
  JsonObject& jsonObj = json.as<JsonObject>();
  // ...
});
server.addHandler(handler);

But this just gives me a compile error

   JsonObject& jsonObj = json.as<JsonObject>();

                                            ^

exit status 1
invalid initialization of non-const reference of type 'ArduinoJson::JsonObject& {aka ArduinoJson6120_000001::ObjectRef&}' from an rvalue of type 'ArduinoJson6120_000001::enable_if<true, ArduinoJson6120_000001::ObjectRef>::type {aka ArduinoJson6120_000001::ObjectRef}'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions