Skip to content

Commit 5e57a64

Browse files
committed
Fix: Wrong method in example and .json() for non-POST requests
1 parent 7d8c0b1 commit 5e57a64

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

adafruit_httpserver/request.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ def form_data(self) -> Union[FormData, None]:
302302
return self._form_data
303303

304304
def json(self) -> Union[dict, None]:
305-
"""Body of the request, as a JSON-decoded dictionary."""
306-
return json.loads(self.body) if self.body else None
305+
"""Body of the request, as a JSON-decoded dictionary. Only available for POST requests."""
306+
return json.loads(self.body) if (self.body and self.method == "POST") else None
307307

308308
@property
309309
def _raw_header_bytes(self) -> bytes:

examples/httpserver_neopixel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def change_neopixel_color_handler_post_json(request: Request):
6060
# You can always manually create a Route object and import or register it later.
6161
# Using this approach you can also use the same handler for multiple routes.
6262
post_json_route = Route(
63-
"/change-neopixel-color/json", GET, change_neopixel_color_handler_post_json
63+
"/change-neopixel-color/json", POST, change_neopixel_color_handler_post_json
6464
)
6565

6666

0 commit comments

Comments
 (0)