The modern, object-oriented way to consume REST APIs on ESP32.
Writing HTTP requests on embedded systems shouldn't feel like a chore. The standard approach forces you to manage connection states, handle string buffers manually, and worst of all—allocate massive chunks of RAM just to parse a simple JSON response.
ESP32-HTTP-Client changes the game. It acts as a bridge between your variables and your API. You don't "parse" JSON; you simply tell the client where to put the data.
You've probably written code like this a hundred times:
- Initialize
HTTPClient. - Make the request.
- Check error codes.
http.getString()(Allocating a huge String).- Create a
DynamicJsonDocument(Allocating even more RAM). deserializeJson().- Extract values.
- Hope you didn't run out of heap.
// One line. Zero intermediate strings. Direct memory binding.
client.get("/sensor").getBody("temperature", &myFloatVariable);Why switch? Because your ESP32 deserves better memory management.
| Feature | 🐢 Standard (HTTPClient + ArduinoJson) | ⚡ ESP32-HTTP-Client |
|---|---|---|
| Code Verbosity | High (~15 lines of boilerplate) | Low (1 fluent chain) |
| Memory Usage | Heavy (Stores full payload + JSON Tree) | Lightweight (Stream parsing, no buffering) |
| Syntax | Procedural & Clunky | Fluent & Object-Oriented |
| JSON Parsing | Requires deserializeJson() |
Automatic (Direct binding) |
| Developer Joy | 😫 Frustrating | 🤩 Effortless |
- 🔗 Fluent Chaining: Build requests naturally:
.get().query().getBody(). - 💉 Direct Injection: Key values from JSON are injected directly into standard C types (
int,float,bool,char*). - 📉 Zero Overhead: We don't store the JSON. We read it as it arrives and extract what you need.
- 🛠️ Full REST Support:
GET,POST,PUT,DELETEare first-class citizens. - 🧩 IoT Ready: Perfect for connecting your ESP32 to cloud backends, Firebase, AWS API Gateway, or your custom Node.js/Python servers.
#include <WiFi.h>
#include "ESP32HTTPClient.h"
ESP32HTTPClient client("https://jsonplaceholder.typicode.com");
void setup() {
Serial.begin(115200);
WiFi.begin("SSID", "PASS");
while (WiFi.status() != WL_CONNECTED) delay(100);
// Prepare a variable
int userId = 0;
// Fetch data
// API returns: { "userId": 1, "id": 1, "title": "..." }
client.get("/todos/1").getBody("userId", &userId);
Serial.printf("User ID fetched from API: %d\n", userId);
}
void loop() {}ESP32HTTPClient client("https://api.example.com");Specify the port as the second argument if your API runs on a non-standard port.
ESP32HTTPClient client("http://my-local-server.local", 8080);Don't mess with string concatenation (?id= + String(id) + &val=...). Let the builder do it.
float temperature;
bool active;
// Request: GET /climate?room=living_room&sensor=dht22
client.get("/climate")
.query("room", "living_room")
.query("sensor", "dht22")
.getBody("temp", &temperature) // Finds "temp": 24.5
.getBody("active", &active); // Finds "active": trueSending data is just as easy as receiving it.
int newId;
// Request: POST /users
// Body: { "name": "Pedro", "role": "admin", "age": 21 }
client.post("/users")
.body("name", "Pedro")
.body("role", "admin")
.body("age", 21)
.getBody("id", &newId); // Get the ID created by the serverComplete control over your resources.
// PUT: Update status
client.update("/lights/1").body("state", "OFF");
// DELETE: Remove a log
client.del("/logs/system_error.log");Explore the full capabilities in the examples/ directory:
- SimpleGET - Basic data fetching.
- PostRequest - Sending data to an API.
- PutRequest - Updating server resources.
- DeleteRequest - Deleting data.
- PortSelection - Connecting to a custom port.
Don't forget to star ⭐ this repo if it saved you time!