#include <WiFi.h>
#include <HTTPClient.h>
#define WIFI_SSID "Wokwi-GUEST"
#define WIFI_PASSWORD ""
#define WIFI_CHANNEL 6

void getAPI(){
  if(WiFi.status()== WL_CONNECTED){
    HTTPClient http;   
    http.begin("http://jsonplaceholder.typicode.com/users/1");
    http.addHeader("Content-Type", "text/plain");
    // int httpResponseCode = http.POST("POSTING from ESP32");
    int httpResponseCode = http.GET();
    if(httpResponseCode>0){
      String response = http.getString();
      Serial.println(httpResponseCode);
      Serial.println(response);
    }else{
      Serial.print("Error on sending POST: ");
      Serial.println(httpResponseCode);
    }
    http.end();
  }else{
    Serial.println("Error in WiFi connection");   
  }
}

void setup(void) {
  Serial.begin(115200);
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD, WIFI_CHANNEL);
  Serial.print("Connecting to WiFi ");
  Serial.print(WIFI_SSID);
  while (WiFi.status() != WL_CONNECTED) {
    delay(100);
    Serial.print(".");
  }
  Serial.println(" Connected!");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  //delay(10000);
  getAPI();
}

void loop(void) {
  delay(5000);
  
}