ESP32 WebServer Library

Home / References ESP32 Library 

The ESP32 WebServer Library provides a comprehensive set of methods for creating and managing web servers on ESP32 microcontrollers. This reference guide categorizes these methods based on their functionality to help you quickly find the methods you need for your IoT projects.

Server Operation

  • begin() – Starts the server to listen for incoming client connections or on a specific port.
  • close() – Closes the server and stops accepting new connections.
  • stop() – Stops the server and terminates all client connections.

Client Handling

  • handleClient() – Processes incoming client requests and dispatches them to handlers.
  • send() – Sends an HTTP response with a status code, content type, and body.
  • send_P() – Sends a response with content stored in program memory (PROGMEM).
  • setContentLength() – Sets the “Content-Length” header for the response.
  • sendHeader() – Adds a custom header to the response.
  • sendContent() – Sends additional content as part of the response body.
  • sendContent_P() – Sends PROGMEM content as part of the response.
  • streamFile() – Streams a file as the response with a specified content type and status code.

Routing and Handlers

  • on() – Registers a handler function for a specific URI, method, or file upload.
  • onNotFound()- Sets a handler for requests to undefined routes (404).
  • onFileUpload() – Sets a handler for file upload requests.
  • serveStatic() – Serves static files from a filesystem at a specified URI.
  • addHandler() – Adds a custom request handler to the server.
  • removeHandler() – Removes a previously added request handler.

Authentication

Request Information

  • uri() – Returns the URI of the current client request.
  • method() – Returns the HTTP method (e.g., GET, POST) of the current request.
  • clientContentLength() – Returns the “Content-Length” value from the client’s HTTP header.
  • arg() – Gets the value of a request argument by its name or index.
  • argName() – Retrieves the name of a request argument by its index.
  • args() – Returns the total number of arguments in the current request.
  • hasArg() – Checks if a specific argument exists in the request.
  • hostHeader() – Retrieves the host header value from the request, if available.
  • version() – Gets the HTTP version string of the current request.
  • client() – Returns a reference to the current client connection.
  • upload() – Returns a reference to the current file upload data.

Response Information

  • responseCode() – Returns the HTTP response code set for the current response.
  • responseHeaders() – Gets the number of headers in the current response.
  • responseHeader() – Retrieves a response header value by name or index.
  • responseHeaderName() – Retrieves a response header name by index.
  • hasResponseHeader() – Checks if a specific response header exists.
  • responseCodeToString() – Converts an HTTP response code to its string representation (e.g., “200 OK”).

Request Header Management

  • collectHeaders() – Specifies which request headers to collect during processing.
  • collectAllHeaders() – Collects all headers from the current request.
  • header() – Gets the value of a specific request header by name or index.
  • headerName() – Retrieves the name of a request header by its index.
  • headers() – Returns the total number of headers in the current request.
  • hasHeader() – Checks if a specific header exists in the request.

Server Configuration

  • enableDelay() – Enables or disables delay in server responses for debugging or testing.
  • enableCORS() – Enables Cross-Origin Resource Sharing (CORS) support.
  • enableCrossOrigin() – Alternative method to enable CORS support.
  • enableETag() – Enables ETag support with an optional custom ETag generation function.

Middleware

  • addMiddleware() – Adds a middleware instance or function to process requests/responses.
  • removeMiddleware() – Removes a previously added middleware instance.

Utility

  • urlDecode() – Decodes a URL-encoded string into plain text.

ESP32 Library Index

ESP32 Arduino Core Library


FAQ

Ready to experiment and explore more about ESP32? Visit our website’s All About ESP32 Resources Hub, packed with tutorials, guides, and tools to inspire your maker journey. Experiment, explore, and elevate your skills with everything you need to master this powerful microcontroller platform!

error: Content is protected !!