7
7
import socketpool
8
8
import wifi
9
9
10
- from adafruit_httpserver import Server , Request , Response , GET , POST
10
+ from adafruit_httpserver import Server , Route , Request , Response , GET , POST
11
11
12
12
13
13
pool = socketpool .SocketPool (wifi .radio )
@@ -43,7 +43,6 @@ def change_neopixel_color_handler_post_body(request: Request):
43
43
return Response (request , f"Changed NeoPixel to color ({ r } , { g } , { b } )" )
44
44
45
45
46
- @server .route ("/change-neopixel-color/json" , POST )
47
46
def change_neopixel_color_handler_post_json (request : Request ):
48
47
"""Changes the color of the built-in NeoPixel using JSON POST body."""
49
48
@@ -55,7 +54,6 @@ def change_neopixel_color_handler_post_json(request: Request):
55
54
return Response (request , f"Changed NeoPixel to color ({ r } , { g } , { b } )" )
56
55
57
56
58
- @server .route ("/change-neopixel-color/<r>/<g>/<b>" , GET )
59
57
def change_neopixel_color_handler_url_params (
60
58
request : Request , r : str = "0" , g : str = "0" , b : str = "0"
61
59
):
@@ -67,5 +65,15 @@ def change_neopixel_color_handler_url_params(
67
65
68
66
return Response (request , f"Changed NeoPixel to color ({ r } , { g } , { b } )" )
69
67
68
+ url_params_route = Route (
69
+ "/change-neopixel-color/<r>/<g>/<b>" , GET , change_neopixel_color_handler_url_params
70
+ )
71
+
72
+ # Alternative way of registering routes.
73
+ server .add_routes ([
74
+ Route ("/change-neopixel-color/json" , GET , change_neopixel_color_handler_post_json ),
75
+ url_params_route ,
76
+ ])
77
+
70
78
71
79
server .serve_forever (str (wifi .radio .ipv4_address ))
0 commit comments