@@ -8,6 +8,7 @@ It also manually connects to the WiFi network.
88
99.. literalinclude :: ../examples/httpserver_simpletest_manual.py
1010 :caption: examples/httpserver_simpletest_manual.py
11+ :emphasize-lines: 12-17
1112 :linenos:
1213
1314Although there is nothing wrong with this approach, from the version 8.0.0 of CircuitPython,
@@ -39,13 +40,15 @@ In order to save memory, we are unregistering unused MIME types and registering
3940
4041.. literalinclude :: ../examples/httpserver_static_files_serving.py
4142 :caption: examples/httpserver_static_files_serving.py
43+ :emphasize-lines: 12-18,23-26
4244 :linenos:
4345
4446You can also serve a specific file from the handler.
4547By default ``Response.send_file() `` looks for the file in the server's ``root_path `` directory, but you can change it.
4648
4749.. literalinclude :: ../examples/httpserver_handler_serves_file.py
4850 :caption: examples/httpserver_handler_serves_file.py
51+ :emphasize-lines: 22-23
4952 :linenos:
5053
5154.. literalinclude :: ../examples/home.html
@@ -65,6 +68,7 @@ a running total of the last 10 samples.
6568
6669.. literalinclude :: ../examples/httpserver_start_and_poll.py
6770 :caption: examples/httpserver_start_and_poll.py
71+ :emphasize-lines: 26-39
6872 :linenos:
6973
7074Server with MDNS
@@ -77,6 +81,7 @@ In this example, the server is accessible via ``http://custom-mdns-hostname/`` a
7781
7882.. literalinclude :: ../examples/httpserver_mdns.py
7983 :caption: examples/httpserver_mdns.py
84+ :emphasize-lines: 12-14
8085 :linenos:
8186
8287Handling different methods
@@ -93,20 +98,23 @@ In example below, handler for ``/api`` route will be called when any of ``GET``,
9398
9499.. literalinclude :: ../examples/httpserver_methods.py
95100 :caption: examples/httpserver_methods.py
101+ :emphasize-lines: 8,15
96102 :linenos:
97103
98104Change NeoPixel color
99105---------------------
100106
101- If you want your code to do more than just serve web pages,
102- use the start/poll methods as shown in this example.
107+ In your handler function you can access the query/GET parameters using ``request.query_params ``.
108+ This allows you to pass data to the handler function and use it in your code.
109+ Alternatively you can use URL parameters, which are described later in this document.
103110
104111For example by going to ``/change-neopixel-color?r=255&g=0&b=0 `` or ``/change-neopixel-color/255/0/0 ``
105112you can change the color of the NeoPixel to red.
106113Tested on ESP32-S2 Feather.
107114
108115.. literalinclude :: ../examples/httpserver_neopixel.py
109116 :caption: examples/httpserver_neopixel.py
117+ :emphasize-lines: 24-26,34-35
110118 :linenos:
111119
112120Get CPU information
@@ -117,6 +125,7 @@ That makes it easy to use the data in other applications.
117125
118126.. literalinclude :: ../examples/httpserver_cpu_information.py
119127 :caption: examples/httpserver_cpu_information.py
128+ :emphasize-lines: 28-29
120129 :linenos:
121130
122131Chunked response
@@ -127,6 +136,7 @@ To use it, you need to set the ``chunked=True`` when creating a ``Response`` obj
127136
128137.. literalinclude :: ../examples/httpserver_chunked.py
129138 :caption: examples/httpserver_chunked.py
139+ :emphasize-lines: 21-26
130140 :linenos:
131141
132142URL parameters
@@ -149,6 +159,7 @@ Also note that the names of the function parameters **have to match** with the o
149159
150160.. literalinclude :: ../examples/httpserver_url_parameters.py
151161 :caption: examples/httpserver_url_parameters.py
162+ :emphasize-lines: 30-34
152163 :linenos:
153164
154165Authentication
@@ -160,11 +171,13 @@ If you want to apply authentication to the whole server, you need to call ``.req
160171
161172.. literalinclude :: ../examples/httpserver_authentication_server.py
162173 :caption: examples/httpserver_authentication_server.py
174+ :emphasize-lines: 8,11-15,19
163175 :linenos:
164176
165177On the other hand, if you want to apply authentication to a set of routes, you need to call ``require_authentication `` function.
166178In both cases you can check if ``request `` is authenticated by calling ``check_authentication `` on it.
167179
168180.. literalinclude :: ../examples/httpserver_authentication_handlers.py
169181 :caption: examples/httpserver_authentication_handlers.py
182+ :emphasize-lines: 9-15,21-25,33,44,57
170183 :linenos:
0 commit comments