diff --git a/src/turbosloth/__main__.py b/src/turbosloth/__main__.py index 7c3498b..14c21d8 100644 --- a/src/turbosloth/__main__.py +++ b/src/turbosloth/__main__.py @@ -14,6 +14,5 @@ async def index(req: BasicRequest) -> BasicResponse: @app.get("/user/") async def get_user(req: BasicRequest) -> BasicResponse: - text = f"User ID: ".encode("utf-8") - - return BasicResponse(200, {}, b'Hello, User!') + print(req.query) + return BasicResponse(200, {}, f'Hello, User {req.query["id"]}!'.encode()) diff --git a/src/turbosloth/types.py b/src/turbosloth/types.py index 4d728b8..b4e16a2 100644 --- a/src/turbosloth/types.py +++ b/src/turbosloth/types.py @@ -32,7 +32,7 @@ class BasicRequest: method: str path: str headers: dict[str, str] - query: dict[str, list[str]] + query: dict[str, list[str] | str] body: dict[str, Any] @classmethod @@ -43,7 +43,14 @@ class BasicRequest: for key, value in scope.get('headers', []): headers[key.decode('latin1')] = value.decode('latin1') - query = urllib.parse.parse_qs(scope['query_string'].decode('latin1')) + qs = scope['query_string'].decode('latin1') + print(qs) + query_raw = urllib.parse.parse_qs(qs) + query = {} + for k, v in query_raw.items(): + if len(v) == 1: + v = v[0] + query[k] = v body = scope['body']