Skip to content

Commit 0eef2e8

Browse files
committed
Changes/fixes in docs
1 parent 7c6ae2a commit 0eef2e8

File tree

1 file changed

+46
-6
lines changed

1 file changed

+46
-6
lines changed

docs/examples.rst

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ Simple Test
33

44
**All examples in this document are using** ``Server`` **in** ``debug`` **mode.**
55
**This mode is useful for development, but it is not recommended to use it in production.**
6+
**More about Debug mode at the end of Examples section.**
67

78
This is the minimal example of using the library.
89
This example is serving a simple static text message.
@@ -61,8 +62,8 @@ By default ``Response.send_file()`` looks for the file in the server's ``root_pa
6162
:lines: 5-
6263
:linenos:
6364

64-
Tasks in the background
65-
-----------------------
65+
Tasks between requests
66+
----------------------
6667

6768
If you want your code to do more than just serve web pages,
6869
use the ``.start()``/``.poll()`` methods as shown in this example.
@@ -73,14 +74,15 @@ a running total of the last 10 samples.
7374

7475
.. literalinclude:: ../examples/httpserver_start_and_poll.py
7576
:caption: examples/httpserver_start_and_poll.py
76-
:emphasize-lines: 26-39
77+
:emphasize-lines: 25,34
7778
:linenos:
7879

7980
Server with MDNS
8081
----------------
8182

82-
It is possible to use the MDNS protocol to make the server
83-
accessible via a hostname in addition to an IP address.
83+
It is possible to use the MDNS protocol to make the server accessible via a hostname in addition
84+
to an IP address. It is worth noting that it takes a bit longer to get the response from the server
85+
when accessing it via the hostname.
8486

8587
In this example, the server is accessible via ``http://custom-mdns-hostname/`` and ``http://custom-mdns-hostname.local/``.
8688

@@ -154,6 +156,10 @@ URL parameters
154156
--------------
155157

156158
Alternatively to using query parameters, you can use URL parameters.
159+
They are a better choice when you want to perform different actions based on the URL.
160+
Query/GET parameters are better suited for modifying the behaviour of the handler function.
161+
162+
Of course it is only a suggestion, you can use them interchangeably and/or both at the same time.
157163

158164
In order to use URL parameters, you need to wrap them inside ``<>`` in ``Server.route``, e.g. ``<my_parameter>``.
159165

@@ -177,6 +183,7 @@ Authentication
177183
--------------
178184

179185
In order to increase security of your server, you can use ``Basic`` and ``Bearer`` authentication.
186+
Remember that it is **not a replacement for HTTPS**, traffic is still sent **in plain text**, but it can be used to protect your server from unauthorized access.
180187

181188
If you want to apply authentication to the whole server, you need to call ``.require_authentication`` on ``Server`` instance.
182189

@@ -203,8 +210,41 @@ Using ``.serve_forever()`` for this is not possible because of it's blocking beh
203210
Each server **must have a different port number**.
204211

205212
In combination with separate authentication and diffrent ``root_path`` this allows creating moderately complex setups.
213+
You can share same handler functions between servers or use different ones for each server.
206214

207215
.. literalinclude:: ../examples/httpserver_multiple_servers.py
208216
:caption: examples/httpserver_multiple_servers.py
209-
:emphasize-lines: 13-14,17,26,35-36,51-52,57-58
217+
:emphasize-lines: 13-14,17,26,35-36,48-49,54-55
210218
:linenos:
219+
220+
Debug mode
221+
----------------
222+
223+
It is highly recommended to **disable debug mode in production**.
224+
225+
During development it is useful to see the logs from the server.
226+
You can enable debug mode by setting ``debug=True`` on ``Server`` instance or in constructor,
227+
it is disabled by default.
228+
229+
Debug mode prints messages on server startup, when a request is received and if exception
230+
occurs during handling of the request in ``.serve_forever()``.
231+
232+
This is how the logs might look like when debug mode is enabled::
233+
234+
Started development server on http://192.168.0.100:80
235+
192.168.0.101 -- GET / 194
236+
192.168.0.101 -- GET /example 194
237+
192.168.0.102 -- POST /api 241
238+
Traceback (most recent call last):
239+
...
240+
File "code.py", line 55, in example_handler
241+
KeyError: non_existent_key
242+
192.168.0.103 -- GET /index.html 242
243+
...
244+
245+
246+
If you need more information about the request or you want it in a different format you can modify
247+
functions at the bottom of ``adafruit_httpserver/server.py`` that start with ``_debug_...``.
248+
249+
NOTE:
250+
*This is an advanced usage that might change in the future. It is not recommended to modify other parts of the code.*

0 commit comments

Comments
 (0)