Source: https://mokxi.com/libraries/espasyncwebserver
Updated: 2026-11-22

Libraries / Network

Arduino library · Network

# ESPAsyncWebServer: a web server that needs no handleClient()

Yes, with limits. You can use the ESP Async WebServer library online in Mokxi with nothing to install, and the sketch runs in your browser. Part of it is not simulated, and the notes below say which. The example below, "ESP32 async web server: BME280, slider and relay", runs on the ESP32 DevKit V1.

Run the example in Mokxi See the calls

Built in on Mokxi: #include <ESPAsyncWebServer.h> and it builds, with nothing to install. Free, and no account needed.

## What ESP Async WebServer does

ESPAsyncWebServer, now kept by the ESP32Async group, is an asynchronous web server for the ESP32 and ESP8266. Unlike the core WebServer, where loop() must call server.handleClient() to answer anyone, this one is event driven: AsyncTCP (or ESPAsyncTCP on the ESP8266) receives requests in the background and calls your handlers, so loop() can be empty or busy with sensors.

You create AsyncWebServer server(80), register a handler per path with server.on(), and call server.begin(). Each handler gets an AsyncWebServerRequest pointer: read form fields with hasParam() and getParam(), and answer with request->send(). Pages stored in flash can carry %NAME% placeholders that a processor function fills in as the page goes out, and serveStatic() hands out files from LittleFS.

The example serves a page with a live uptime placeholder, a GET form and a POST form to the editor’s Web panel, on an ESP32-C3. What is not here: AsyncWebSocket and AsyncEventSource compile but no client connects, request headers other than Location are not passed, uploads and regex paths are missing, and a reply stops at 4 KB. A handler must also send before it returns.

Library Manager name | ESP Async WebServer

Author | ESP32Async

Include | #include <ESPAsyncWebServer.h>
#include <AsyncJson.h>
#include <AsyncWebSocket.h>
#include <AsyncEventSource.h>

Boards | ESP32-C3, ESP32-C6, Seeed XIAO ESP32-C3, ESP32-C3 SuperMini, Seeed XIAO ESP32-C6, ESP32 DevKit, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, ESP32-S3-DevKitC-1, Seeed XIAO ESP32-S3, Arduino Nano ESP32, ESP32-S3-CAM, ESP8266 NodeMCU

In the simulator | Runs, with a gap the note below names.

## Install it

It builds on ESP32-C3, ESP32-C6, Seeed XIAO ESP32-C3, ESP32-C3 SuperMini, Seeed XIAO ESP32-C6, ESP32 DevKit, ESP32-DevKitC V4, LOLIN32 Lite, Wemos D1 R32, Cheap Yellow Display, TTGO T-Display, ESP32-S3-DevKitC-1, Seeed XIAO ESP32-S3, Arduino Nano ESP32, ESP32-S3-CAM, ESP8266 NodeMCU.

In Mokxi it is built in: #include <ESPAsyncWebServer.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "ESP Async WebServer" by ESP32Async from the Arduino IDE’s Library Manager (Sketch, Include Library, Manage Libraries), or add ESP Async WebServer to lib_deps in PlatformIO. Mokxi follows the calls of release 3.12.1, so a sketch written here builds there too.

What to know in the simulator: WebSockets (AsyncWebSocket) and server-sent events (AsyncEventSource) compile and are not simulated: no client connects. A handler must send before it returns. Headers other than Location are not sent, none reach a handler, authentication passes, regex paths and file uploads are not here, and replies stop at 4 KB.

- ESP32-C3
- ESP32-C6
- Seeed XIAO ESP32-C3
- ESP32-C3 SuperMini
- Seeed XIAO ESP32-C6
- ESP32 DevKit
- ESP32-DevKitC V4
- LOLIN32 Lite
- Wemos D1 R32
- Cheap Yellow Display
- TTGO T-Display
- ESP32-S3-DevKitC-1
- Seeed XIAO ESP32-S3
- Arduino Nano ESP32
- ESP32-S3-CAM
- ESP8266 NodeMCU

## The calls you will use

In the order a sketch meets them.

### AsyncWebServer server(80)

Creates the server on port 80. It does not listen until server.begin().

### server.on("/", HTTP_GET, handleRoot)

Registers a handler for a path and method. A lambda is the common style: [](AsyncWebServerRequest *request) { ... }.

### request->send(200, "text/plain", "Hello")

Answers with a status code, content type and body. Every request must get exactly one send().

### request->send_P(200, "text/html", index_html, processor)

Sends a page from flash, replacing each %NAME% with what processor() returns for NAME.

### request->hasParam("message", true)

Asks whether a form field arrived. Pass true for a POST body field, leave it out for a ?query field.

### request->getParam("message")->value()

The field’s value as a String. getParam() returns a null pointer when the field is missing, so check hasParam() first.

### server.serveStatic("/", LittleFS, "/").setDefaultFile("index.html")

Serves files from LittleFS under a URL prefix, with index.html for the bare path.

### server.onNotFound(notFound)

The handler for every path nothing else matched, usually a 404 reply.

### server.begin()

Starts listening. Call it after WiFi is connected and every on() is registered.

## Example: ESP32 async web server: BME280, slider and relay

On the ESP32 DevKit V1. It runs in the browser exactly as printed.

sketch.ino · ESP32 DevKit V1

The sketch is cut short here; the editor has every line of it.

Open it in the editor, wired and ready to run · ESP32 async web server: BME280, slider and relay: the project page

## Common errors and how to fix them

### The board resets with a watchdog error when a page is opened

A handler runs inside the TCP task, and a delay(), a long sensor read or a blocking HTTP call there starves it. Keep handlers short: set a flag or store the request’s values, then do the slow work in loop().

### The page shows %UPTIME% or breaks where the CSS has percentages

Placeholders are only filled when you pass a processor to send_P() or send(). Once you do, every % in the page is read as a placeholder marker, so write a literal percent sign in CSS as %%.

### Crash or Guru Meditation Error when a form is submitted empty

getParam() returned nullptr because the field was missing, and ->value() dereferenced it. Test hasParam() first, and pass true to both for fields in a POST body, since the default only looks at the URL query.

### AsyncTCP.h: No such file or directory on an ESP8266

AsyncTCP is the ESP32 transport. On the ESP8266 include <ESPAsyncTCP.h> instead, behind #ifdef ESP32 as the example does, and install the ESP32Async versions of both so they match.

## Questions and answers

### Async or the built-in WebServer?

The built-in WebServer is simpler and answers only while loop() calls handleClient(). The async server answers in the background and handles several clients at once, at the cost of handlers that must never block.

### Which fork should I install?

The ESP32Async organization’s ESPAsyncWebServer and AsyncTCP are the maintained ones. Older tutorials link to me-no-dev’s repositories, which work with the same code but are no longer updated.

## Keep going

### Learn

- Connect a Board to WiFi and Serve a Page
- ESP32 Not Connecting to WiFi: Causes and Fixes

### More network libraries

- PubSubClient
- MQTT
- Blynk
- ThingSpeak
- WiFiManager
- WiFi, HTTPClient and WebServer (ESP32 core)
- WebSockets
- NTPClient

Every built-in library · Open the editor

## Try ESP Async WebServer without installing anything

Open the example, change the sketch, and keep your version in a free account.

Start building free

Open the editor
