Looking to use REST API for project

Hello everyone,
I have an ESP32-S3 Display board (Crowpanel 5" from Elecrow) that I have built a UI in LVGL using Squareline Studio. I am trying to learn how to use REST API and Http Commands in order to take a button in LVGL, on the UI, and have it Toggle an entity in HA, like toggle.desklamp for example. I am relatively naive to using both http requests and REST API and was wondering if someone could point me to some good resources to learn from in order to realize my project.
I have found a Youtube Video that is doing exactly this, but the problem is that the uploader doesn’t explain it in enough detail for me to fully understand it.

From what I understand, he’s setting up a function to set an entity state via an http client, and then calling on that function later on in LVGL.

This is what I have as part of my main .ino file, literally copied from the video.

void set_entity_state(const char *entity_id, const char *state) {
  if(WiFi.status()== WL_CONNECTED){
    HTTPClient http;
    String url = "http://http://192.168.0.151:8123/api/states/";
    url.concat(entity_id);
    http.begin(url);
    http.addHeader("Authorization", TOKEN);  //TOKEN is a const char using a long lived access token
    http.addHeader("Content-Type", "application/json");
    DynamicJsonDocument root(200);
    root["state"] = (String)state;
    char data[200];
    serializeJson(root, data, 200);
    http.POST(data);
    http.end();
  }
}

Can someone explain to me what this code is doing?

Thanks

See here:

Your code appears to be building a POST request to /api/states/<entity_id> (the first “green box” POST section in that document).

So you’d call set_entity_state with an entity ID and a state value, and the function would use the API to make that happen in Home Assistant. Doesn’t matter whether the entity already exists or not.

Obviously, make sure the IP address in the code matches your LAN address for your HA installation; and you need to create and hard-code in your long-life token in place of TOKEN.

thank you for the reply