-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add doc for ESP8266WebServer #5400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6951500
Add doc for ESP8266WebServer
dav1901 1194981
Merge branch 'master' into doc
dav1901 505e0bf
Merge branch 'master' into doc
devyte 24b9740
Merge branch 'master' into doc
dav1901 6aadb9d
Merge branch 'master' into doc
dav1901 6db7a8c
Merge branch 'master' into doc
devyte c67a16e
Use tabs
dav1901 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
|
||
ESP8266 Web Server | ||
================== | ||
|
||
The WebServer class found in ``ESP8266WebServer.h`` header, is a simple web server that knows how to handle HTTP requests such as GET and POST and can only support one simultaneous client. | ||
|
||
Usage | ||
----- | ||
|
||
Class Constructor | ||
~~~~~~~~~~~~~~~~~ | ||
|
||
.. code:: cpp | ||
|
||
ESP8266WebServer server(80); | ||
|
||
Creates the ESP8266WebServer class object. | ||
|
||
*Parameters:* | ||
|
||
host IP address: ``IPaddress addr`` (optional) | ||
|
||
host port number: ``int port`` (default is the standard HTTP port 80) | ||
|
||
Basic Operations | ||
~~~~~~~~~~~~~~~~ | ||
|
||
Starting the server | ||
^^^^^^^^^^^^^^^^^^^ | ||
|
||
.. code:: cpp | ||
|
||
void begin(); | ||
|
||
Handling incoming client requests | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
.. code:: cpp | ||
|
||
void handleClient(); | ||
|
||
Disabling the server | ||
^^^^^^^^^^^^^^^^^^^^ | ||
|
||
.. code:: cpp | ||
|
||
void close(); | ||
void stop(); | ||
|
||
Both methods function the same | ||
|
||
Client request handlers | ||
^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
.. code:: cpp | ||
|
||
void on(); | ||
void addHandler(); | ||
void onNotFound(); | ||
void onFileUpload(); | ||
|
||
*Example:* | ||
|
||
.. code:: cpp | ||
|
||
server.on("/", handlerFunction); | ||
server.onNotFound(handlerFunction); // called when handler is not assigned | ||
server.onFileUpload(handlerFunction); // handle file uploads | ||
|
||
Sending responses to the client | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
.. code:: cpp | ||
|
||
void send(); | ||
void send_P(); | ||
|
||
*Parameters:* | ||
|
||
``code`` - HTTP response code, can be ``200`` or ``404``, etc. | ||
|
||
``content_type`` - HTTP content type, like ``"text/plain"`` or ``"image/png"``, etc. | ||
|
||
``content`` - actual content body | ||
|
||
Advanced Options | ||
~~~~~~~~~~~~~~~~ | ||
|
||
Getting information about request arguments | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
.. code:: cpp | ||
|
||
const String & arg(); | ||
const String & argName(); | ||
int args(); | ||
bool hasArg(); | ||
|
||
``arg`` - get request argument value | ||
|
||
``argName`` - get request argument name | ||
|
||
``args`` - get arguments count | ||
|
||
``hasArg`` - check if argument exist | ||
|
||
Getting information about request headers | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
.. code:: cpp | ||
|
||
const String & header(); | ||
const String & headerName(); | ||
const String & hostHeader(); | ||
int headers(); | ||
bool hasHeader(); | ||
|
||
|
||
``header`` - get request header value | ||
|
||
``headerName`` - get request header name | ||
|
||
``hostHeader`` - get request host header if available, else empty string | ||
|
||
``headers`` - get header count | ||
|
||
``hasHeader`` - check if header exist | ||
|
||
Authentication | ||
^^^^^^^^^^^^^^ | ||
|
||
.. code:: cpp | ||
|
||
bool authenticate(); | ||
void requestAuthentication(); | ||
|
||
``authenticate`` - server authentication, returns true if client is authenticated else false | ||
|
||
``requestAuthentication`` - sends authentication failure response to the client | ||
|
||
*Example Usage:* | ||
|
||
.. code:: cpp | ||
|
||
if(!server.authenticate(username, password)){ | ||
server.requestAuthentication(); | ||
} | ||
|
||
|
||
Other Function Calls | ||
~~~~~~~~~~~~~~~~~~~~ | ||
|
||
.. code:: cpp | ||
|
||
const String & uri(); // get the current uri | ||
HTTPMethod method(); // get the current method | ||
WiFiClient client(); // get the current client | ||
HTTPUpload & upload(); // get the current upload | ||
void setContentLength(); // set content length | ||
void sendHeader(); // send HTTP header | ||
void sendContent(); // send content | ||
void sendContent_P(); | ||
void collectHeaders(); // set the request headers to collect | ||
void serveStatic(); | ||
size_t streamFile(); | ||
|
||
For code samples enter `here <https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WebServer/examples>`__ . | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.