Skip to content

Commit e5f506b

Browse files
committed
Added Request.json()
1 parent 752dcaf commit e5f506b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

adafruit_httpserver/request.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
except ImportError:
1818
pass
1919

20+
import json
21+
2022
from .headers import Headers
2123

2224

@@ -115,6 +117,10 @@ def body(self) -> bytes:
115117
def body(self, body: bytes) -> None:
116118
self.raw_request = self._raw_header_bytes + b"\r\n\r\n" + body
117119

120+
def json(self) -> Union[dict, None]:
121+
"""Body of the request, as a JSON-decoded dictionary."""
122+
return json.loads(self.body) if self.body else None
123+
118124
@property
119125
def _raw_header_bytes(self) -> bytes:
120126
"""Returns headers bytes."""

0 commit comments

Comments
 (0)