Skip to content

Commit 5e7c315

Browse files
committed
Update website
1 parent 0185ffc commit 5e7c315

9 files changed

Lines changed: 92 additions & 151 deletions

File tree

docs/eventsource.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
The server includes EventSource (Server-Sent Events) plugin which can be used to send short text events to the browser.
66
Difference between EventSource and WebSockets is that EventSource is single direction, text-only protocol.
77

8-
See the [ServerSentEvents example here](../examples/ServerSentEvents/ServerSentEvents.ino).
8+
See the [ServerSentEvents example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/ServerSentEvents/ServerSentEvents.ino).
99

1010
### Setup Event Source on the server
1111

docs/filters.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Two filter callback are provided for convince:
1010
- `ON_STA_FILTER` - return true when requests are made to the STA (station mode) interface.
1111
- `ON_AP_FILTER` - return true when requests are made to the AP (access point) interface.
1212

13-
See the [Filters example here](../examples/Filters/Filters.ino).
13+
See the [Filters example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/Filters/Filters.ino).
1414

1515
### Serve different site files in AP mode
1616

docs/middleware.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ AsyncMiddlewareFunction complexAuth([](AsyncWebServerRequest* request, ArMiddlew
4040
- `LoggerMiddleware`: to log requests globally or per handler with the same pattern as curl. Will also record request processing time
4141
- `AsyncRateLimitMiddleware`: to limit the number of requests on a windows of time globally or per handler
4242
43-
See the [Middleware example here](../examples/Middleware/Middleware.ino).
43+
See the [Middleware example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/Middleware/Middleware.ino).
4444
4545
### CORS with AsyncCorsMiddleware
4646
@@ -114,7 +114,7 @@ server.addMiddleware(&authMiddleware); // globally add authentication to the ser
114114
myHandler.addMiddleware(&authMiddleware); // add authentication to a specific handler
115115
```
116116

117-
See the [Auth example here](../examples/Auth/Auth.ino).
117+
See the [Auth example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/Auth/Auth.ino).
118118

119119
### Migration to Middleware to improve performance and memory usage
120120

docs/requests.md

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,46 @@ if(request->hasHeader("MyHeader")){
4444
}
4545
```
4646
47-
See the [Headers example here](../examples/Headers/Headers.ino).
47+
See the [Headers example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/Headers/Headers.ino).
48+
49+
## Path Variable
50+
51+
With path variable you can create a custom regex rule for a specific parameter in a route.
52+
For example we want a `sensorId` parameter in a route rule to match only a integer.
53+
54+
```cpp
55+
server.on("^\\/sensor\\/([0-9]+)$", HTTP_GET, [] (AsyncWebServerRequest *request) {
56+
String sensorId = request->pathArg(0);
57+
});
58+
```
59+
60+
_NOTE_: All regex patterns starts with `^` and ends with `$`
61+
62+
To enable the `Path variable` support, you have to define the buildflag `-DASYNCWEBSERVER_REGEX`.
63+
64+
For Arduino IDE create/update `platform.local.txt`:
65+
66+
`Windows`: C:\Users\(username)\AppData\Local\Arduino15\packages\\`{espxxxx}`\hardware\\`espxxxx`\\`{version}`\platform.local.txt
67+
68+
`Linux`: ~/.arduino15/packages/`{espxxxx}`/hardware/`{espxxxx}`/`{version}`/platform.local.txt
69+
70+
Add/Update the following line:
71+
72+
```
73+
compiler.cpp.extra_flags=-DASYNCWEBSERVER_REGEX
74+
```
75+
76+
For platformio modify `platformio.ini`:
77+
78+
```ini
79+
[env:myboard]
80+
build_flags =
81+
-DASYNCWEBSERVER_REGEX
82+
```
83+
84+
_NOTE_: By enabling `ASYNCWEBSERVER_REGEX`, `<regex>` will be included. This will add an 100k to your binary.
85+
86+
See the [URIMatcher example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/URIMatcher/URIMatcher.ino) and [URIMatcherTest example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/URIMatcherTest/URIMatcherTest.ino).
4887

4988
### GET, POST and FILE parameters
5089

@@ -85,7 +124,7 @@ if(request->hasArg("download"))
85124
String arg = request->arg("download");
86125
```
87126
88-
See the [Params example here](../examples/Params/Params.ino).
127+
See the [Params example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/Params/Params.ino).
89128
90129
### FILE Upload handling
91130
@@ -103,7 +142,7 @@ void handleUpload(AsyncWebServerRequest *request, String filename, size_t index,
103142
}
104143
```
105144

106-
See the [Upload example here](../examples/Upload/Upload.ino).
145+
See the [Upload example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/Upload/Upload.ino).
107146

108147
### Body data handling
109148

@@ -138,7 +177,7 @@ AsyncCallbackJsonWebHandler* handler = new AsyncCallbackJsonWebHandler("/rest/en
138177
server.addHandler(handler);
139178
```
140179

141-
See the [Json example here](../examples/Json/Json.ino).
180+
See the [Json example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/Json/Json.ino).
142181

143182
### MessagePack body handling
144183

@@ -155,4 +194,4 @@ AsyncCallbackMessagePackWebHandler* handler = new AsyncCallbackMessagePackWebHan
155194
server.addHandler(handler);
156195
```
157196

158-
See the [MessagePack example here](../examples/MessagePack/MessagePack.ino).
197+
See the [MessagePack example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/MessagePack/MessagePack.ino).

docs/responses.md

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
1616
This will send error 400 instead of 200.
1717
18-
See the [example here](../examples/Replace/Replace.ino).
18+
See the [example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/Replace/Replace.ino).
1919
2020
## Request Continuation
2121
@@ -63,7 +63,7 @@ if (auto request = requestPtr.lock()) {
6363
}
6464
```
6565

66-
See the [RequestContinuation example here](../examples/RequestContinuation/RequestContinuation.ino) and [RequestContinuationComplete example here](../examples/RequestContinuationComplete/RequestContinuationComplete.ino).
66+
See the [RequestContinuation example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/RequestContinuation/RequestContinuation.ino) and [RequestContinuationComplete example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/RequestContinuationComplete/RequestContinuationComplete.ino).
6767

6868
## Responses
6969

@@ -77,7 +77,7 @@ request->redirect("/login");
7777
request->redirect("http://esp8266.com");
7878
```
7979
80-
See the [Redirect example here](../examples/Redirect/Redirect.ino).
80+
See the [Redirect example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/Redirect/Redirect.ino).
8181
8282
### Basic response with HTTP Code
8383
@@ -139,7 +139,7 @@ const char index_html[] PROGMEM = "..."; // large char array, tested with 14k
139139
request->send_P(200, "text/html", index_html, processor);
140140
```
141141

142-
See the [Templates example here](../examples/Templates/Templates.ino).
142+
See the [Templates example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/Templates/Templates.ino).
143143

144144
### Send large webpage from PROGMEM containing templates and extra headers
145145

@@ -291,7 +291,7 @@ request->send(LittleFS, "/index.htm", "text/plain");
291291
request->send(LittleFS, "/index.htm", String(), true);
292292
```
293293
294-
See the [StaticFile example here](../examples/StaticFile/StaticFile.ino).
294+
See the [StaticFile example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/StaticFile/StaticFile.ino).
295295
296296
### Respond with content coming from a File and extra headers
297297
@@ -361,7 +361,7 @@ request->send("text/plain", 128, [](uint8_t *buffer, size_t maxLen, size_t index
361361
});
362362
```
363363

364-
See the [ChunkResponse example here](../examples/ChunkResponse/ChunkResponse.ino).
364+
See the [ChunkResponse example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/ChunkResponse/ChunkResponse.ino).
365365

366366
### Respond with content using a callback and extra headers
367367

@@ -507,7 +507,7 @@ response->addHeader("Server","ESP Async Web Server");
507507
request->send(response);
508508
```
509509

510-
See the [ChunkRequest example here](../examples/ChunkRequest/ChunkRequest.ino) and [ChunkRetryResponse example here](../examples/ChunkRetryResponse/ChunkRetryResponse.ino).
510+
See the [ChunkRequest example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/ChunkRequest/ChunkRequest.ino) and [ChunkRetryResponse example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/ChunkRetryResponse/ChunkRetryResponse.ino).
511511

512512
### Chunked Response containing templates
513513

@@ -585,7 +585,7 @@ response->print("</body></html>");
585585
request->send(response);
586586
```
587587

588-
See the [AsyncResponseStream example here](../examples/AsyncResponseStream/AsyncResponseStream.ino).
588+
See the [AsyncResponseStream example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/AsyncResponseStream/AsyncResponseStream.ino).
589589

590590
### ArduinoJson Basic Response
591591

@@ -624,7 +624,7 @@ response->setLength();
624624
request->send(response);
625625
```
626626

627-
See the [Json example here](../examples/Json/Json.ino).
627+
See the [Json example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/Json/Json.ino).
628628

629629
### MessagePack Response
630630

@@ -643,7 +643,36 @@ response->setLength();
643643
request->send(response);
644644
```
645645
646-
See the [MessagePack example here](../examples/MessagePack/MessagePack.ino).
646+
See the [MessagePack example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/MessagePack/MessagePack.ino).
647+
648+
## Adding Default Headers
649+
650+
In some cases, such as when working with CORS, or with some sort of custom authentication system,
651+
you might need to define a header that should get added to all responses (including static, websocket and EventSource).
652+
The DefaultHeaders singleton allows you to do this.
653+
654+
Example:
655+
656+
```cpp
657+
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", "*");
658+
webServer.begin();
659+
```
660+
661+
_NOTE_: You will still need to respond to the OPTIONS method for CORS pre-flight in most cases. (unless you are only using GET)
662+
663+
This is one option:
664+
665+
```cpp
666+
webServer.onNotFound([](AsyncWebServerRequest *request) {
667+
if (request->method() == HTTP_OPTIONS) {
668+
request->send(200);
669+
} else {
670+
request->send(404);
671+
}
672+
});
673+
```
674+
675+
See the [CORS example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/CORS/CORS.ino).
647676

648677
## Bad Responses
649678

docs/routing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Usage:
121121
server.addRewrite( new OneParamRewrite("/radio/{frequence}", "/radio?f={frequence}") );
122122
```
123123

124-
See the [Rewrite example here](../examples/Rewrite/Rewrite.ino).
124+
See the [Rewrite example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/Rewrite/Rewrite.ino).
125125

126126
## Remove handlers and rewrites
127127

docs/setup.md

Lines changed: 2 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,4 @@
1-
# Setup
2-
3-
## Scanning for available WiFi Networks
4-
5-
```cpp
6-
//First request will return 0 results unless you start scan from somewhere else (loop/setup)
7-
//Do not request more often than 3-5 seconds
8-
server.on("/scan", HTTP_GET, [](AsyncWebServerRequest *request){
9-
String json = "[";
10-
int n = WiFi.scanComplete();
11-
if(n == -2){
12-
WiFi.scanNetworks(true);
13-
} else if(n){
14-
for (int i = 0; i < n; ++i){
15-
if(i) json += ",";
16-
json += "{";
17-
json += "\"rssi\":"+String(WiFi.RSSI(i));
18-
json += ",\"ssid\":\""+WiFi.SSID(i)+"\"";
19-
json += ",\"bssid\":\""+WiFi.BSSIDstr(i)+"\"";
20-
json += ",\"channel\":"+String(WiFi.channel(i));
21-
json += ",\"secure\":"+String(WiFi.encryptionType(i));
22-
json += ",\"hidden\":"+String(WiFi.isHidden(i)?"true":"false");
23-
json += "}";
24-
}
25-
WiFi.scanDelete();
26-
if(WiFi.scanComplete() == -2){
27-
WiFi.scanNetworks(true);
28-
}
29-
}
30-
json += "]";
31-
request->send(200, "application/json", json);
32-
json = String();
33-
});
34-
```
1+
# Server Setup
352

363
## Setting up the server
374

@@ -172,7 +139,7 @@ void loop(){
172139
}
173140
```
174141
175-
**IMPORTANT**: Authentication should now use `AsyncAuthenticationMiddleware` instead of the deprecated methods. See the [How to use authentication with AsyncAuthenticationMiddleware](#how-to-use-authentication-with-asyncauthenticationmiddleware) section.
142+
**IMPORTANT**: Authentication should now use `AsyncAuthenticationMiddleware` instead of the deprecated methods. See the [How to use authentication with AsyncAuthenticationMiddleware](middleware.md#how-to-use-authentication-with-asyncauthenticationmiddleware) section.
176143
177144
### Setup global and class functions as request handlers
178145
@@ -228,97 +195,3 @@ void loop() {
228195
if ( !ws.enabled() )
229196
ws.enable(true);
230197
```
231-
232-
Example of OTA code
233-
234-
```cpp
235-
// OTA callbacks
236-
ArduinoOTA.onStart([]() {
237-
// Clean SPIFFS
238-
SPIFFS.end();
239-
240-
// Clean LittleFS
241-
LittleFS.end();
242-
243-
// Disable client connections
244-
ws.enable(false);
245-
246-
// Advertise connected clients what's going on
247-
ws.textAll("OTA Update Started");
248-
249-
// Close them
250-
ws.closeAll();
251-
252-
});
253-
254-
```
255-
256-
See the [EndBegin example here](../examples/EndBegin/EndBegin.ino).
257-
258-
### Adding Default Headers
259-
260-
In some cases, such as when working with CORS, or with some sort of custom authentication system,
261-
you might need to define a header that should get added to all responses (including static, websocket and EventSource).
262-
The DefaultHeaders singleton allows you to do this.
263-
264-
Example:
265-
266-
```cpp
267-
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", "*");
268-
webServer.begin();
269-
```
270-
271-
_NOTE_: You will still need to respond to the OPTIONS method for CORS pre-flight in most cases. (unless you are only using GET)
272-
273-
This is one option:
274-
275-
```cpp
276-
webServer.onNotFound([](AsyncWebServerRequest *request) {
277-
if (request->method() == HTTP_OPTIONS) {
278-
request->send(200);
279-
} else {
280-
request->send(404);
281-
}
282-
});
283-
```
284-
285-
See the [CORS example here](../examples/CORS/CORS.ino).
286-
287-
### Path variable
288-
289-
With path variable you can create a custom regex rule for a specific parameter in a route.
290-
For example we want a `sensorId` parameter in a route rule to match only a integer.
291-
292-
```cpp
293-
server.on("^\\/sensor\\/([0-9]+)$", HTTP_GET, [] (AsyncWebServerRequest *request) {
294-
String sensorId = request->pathArg(0);
295-
});
296-
```
297-
298-
_NOTE_: All regex patterns starts with `^` and ends with `$`
299-
300-
To enable the `Path variable` support, you have to define the buildflag `-DASYNCWEBSERVER_REGEX`.
301-
302-
For Arduino IDE create/update `platform.local.txt`:
303-
304-
`Windows`: C:\Users\(username)\AppData\Local\Arduino15\packages\\`{espxxxx}`\hardware\\`espxxxx`\\`{version}`\platform.local.txt
305-
306-
`Linux`: ~/.arduino15/packages/`{espxxxx}`/hardware/`{espxxxx}`/`{version}`/platform.local.txt
307-
308-
Add/Update the following line:
309-
310-
```
311-
compiler.cpp.extra_flags=-DASYNCWEBSERVER_REGEX
312-
```
313-
314-
For platformio modify `platformio.ini`:
315-
316-
```ini
317-
[env:myboard]
318-
build_flags =
319-
-DASYNCWEBSERVER_REGEX
320-
```
321-
322-
_NOTE_: By enabling `ASYNCWEBSERVER_REGEX`, `<regex>` will be included. This will add an 100k to your binary.
323-
324-
See the [URIMatcher example here](../examples/URIMatcher/URIMatcher.ino) and [URIMatcherTest example here](../examples/URIMatcherTest/URIMatcherTest.ino).

docs/websockets.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ I recommend to use the official API `AsyncWebSocketMessageBuffer` to retain furt
4040
The server includes a web socket plugin which lets you define different WebSocket locations to connect to
4141
without starting another listening service or using different port
4242

43-
See the [WebSocket example here](../examples/WebSocket/WebSocket.ino) and [WebSocketEasy example here](../examples/WebSocketEasy/WebSocketEasy.ino).
43+
See the [WebSocket example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/WebSocket/WebSocket.ino) and [WebSocketEasy example here](https://github.com/ESP32Async/ESPAsyncWebServer/blob/master/examples/WebSocketEasy/WebSocketEasy.ino).
4444

4545
### Async WebSocket Event
4646

0 commit comments

Comments
 (0)