@@ -1371,48 +1371,40 @@ void loop(){
13711371
13721372### Setup global and class functions as request handlers
13731373
1374- ```arduino
1374+ ```cpp
13751375#include <Arduino.h>
13761376#include <ESPAsyncWebserver.h>
13771377#include <Hash.h>
13781378#include <functional>
13791379
1380- void handleRequest(AsyncWebServerRequest *request)
1381- {
1382- }
1380+ void handleRequest(AsyncWebServerRequest *request){}
13831381
1384- class WebClass
1385- {
1382+ class WebClass {
13861383public :
1387- WebClass(){
1388- };
1384+ AsyncWebServer classWebServer = AsyncWebServer(81);
13891385
1390- AsyncWebServer classWebServer = AsyncWebServer(80) ;
1386+ WebClass(){} ;
13911387
1392- void classRequest (AsyncWebServerRequest *request)
1393- {
1394- }
1388+ void classRequest (AsyncWebServerRequest *request){}
13951389
1396- void begin(){
1390+ void begin(){
1391+ // attach global request handler
1392+ classWebServer.on("/example", HTTP_ANY, handleRequest);
13971393
1398- // attach global request handler
1399- classWebServer.on("/example", HTTP_ANY, handleRequest);
1400-
1401- // attach class request handler
1402- classWebServer.on("/example", HTTP_ANY, std::bind(&WebClass::classRequest, this, std::placeholders::_1));
1403- }
1394+ // attach class request handler
1395+ classWebServer.on("/example", HTTP_ANY, std::bind(&WebClass::classRequest, this, std::placeholders::_1));
1396+ }
14041397};
14051398
14061399AsyncWebServer globalWebServer(80);
14071400WebClass webClassInstance;
14081401
14091402void setup() {
1403+ // attach global request handler
1404+ globalWebServer.on("/example", HTTP_ANY, handleRequest);
14101405
1411- // attach global request handler
1412- globalWebServer.on("/example", HTTP_ANY, handleRequest);
1413-
1414- // attach class request handler
1415- globalWebServer.on("/example", HTTP_ANY, std::bind(&WebClass::classRequest, webClassInstance, std::placeholders::_1));
1406+ // attach class request handler
1407+ globalWebServer.on("/example", HTTP_ANY, std::bind(&WebClass::classRequest, webClassInstance, std::placeholders::_1));
14161408}
14171409
14181410void loop() {
@@ -1422,7 +1414,7 @@ void loop() {
14221414
14231415### Methods for controlling websocket connections
14241416
1425- ``` arduino
1417+ ``` cpp
14261418 // Disable client connections if it was activated
14271419 if ( ws.enabled() )
14281420 ws.enable(false );
@@ -1434,7 +1426,7 @@ void loop() {
14341426
14351427Example of OTA code
14361428
1437- ``` arduino
1429+ ``` cpp
14381430 // OTA callbacks
14391431 ArduinoOTA.onStart([]() {
14401432 // Clean SPIFFS
@@ -1461,7 +1453,7 @@ The DefaultHeaders singleton allows you to do this.
14611453
14621454Example:
14631455
1464- ``` arduino
1456+ ```cpp
14651457DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", "*");
14661458webServer.begin();
14671459```
@@ -1470,12 +1462,12 @@ webServer.begin();
14701462
14711463This is one option:
14721464
1473- ``` arduino
1465+ ``` cpp
14741466webServer.onNotFound([](AsyncWebServerRequest *request) {
1475- if (request->method() == HTTP_OPTIONS) {
1476- request->send(200);
1477- } else {
1478- request->send(404);
1479- }
1467+ if (request->method() == HTTP_OPTIONS) {
1468+ request->send(200);
1469+ } else {
1470+ request->send(404);
1471+ }
14801472});
14811473```
0 commit comments