Repository: HapticX/happyx (language: python)

Issue:
How do query params work?
I've been trying to get query params to work for a while now. But i've had no luck. I'm building out an api server as a way to learn how to use happyx ssr and norm for api development.
Here's what my code looks like:
![image](https://github.com/user-attachments/assets/ba34dc78-b507-475c-93b7-b10b48046ea4)
And here's the terminal output.
![image](https://github.com/user-attachments/assets/855948df-5c91-4cc9-9234-224fb1931948)

I'm unable to access the id variable. 
Here's an image of the scalar ui and the network logs tab. The request goes through fine, but i can't access the variable. 

![image](https://github.com/user-attachments/assets/5831070b-a3f8-44d0-9941-d04667eccedb)

It also isn't showing up in the query object as you can see below (i'm using a middleware to print the urlPath and query)
![image](https://github.com/user-attachments/assets/61ce1c51-7493-45b6-bef2-62eede807a82)


Example code will be appreciated. Also, if i can get it to show up in the docs, that'll be nice. I'm aware of `/get/{id:int}` but query params have always been part of my coding style and i'm not comfortable switching to path params.
Thanks.


Discussion / hints:
Query works at the latest happyx version 🤔
```nim
get "/get":
  echo query  # StringTableRef
  echo urlPath  # string
  echo query?id  # string
  return query?id
```

so this working: http://localhost:5000/get?id=123
![image](https://github.com/user-attachments/assets/9903a74c-c7dd-40dc-b2c8-6bc9a2247d6d)
![image](https://github.com/user-attachments/assets/8d10770f-1732-4167-a66a-e17f308c0f85)

try to reinstall happyx
```shell
nimble remove happyx -y
nimble install happyx@#head
```
It only works with the micro and default servers. Httpx and httpbeast don't
work for some reason. My internet here is bad so I'm replying via mail on
my phone.

But do a test and see.

On Tue, Nov 26, 2024, 2:29 AM Ethosa ***@***.***> wrote:

> try to reinstall happyx
>
> nimble remove happyx -y
> nimble install happyx@#head
>
> —
> Reply to this email directly, view it on GitHub
> <https://github.com/HapticX/happyx/issues/378#issuecomment-2499385204>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AU6YHY62PXPDR3GHULBYUTT2CPFJFAVCNFSM6AAAAABSPCHIOSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIOJZGM4DKMRQGQ>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>

Here's are screenshots

**Micro (works)**
![Screenshot 2024-11-26 130441](https://github.com/user-attachments/assets/6dacd165-eb68-4751-a738-5cf553e67e6d)

**httpx (Not working)**
![Screenshot 2024-11-26 130351](https://github.com/user-attachments/assets/6ae730b9-544f-451a-bc78-500f97aa86e7)

**httpbeast (Not working)**
![Screenshot 2024-11-26 130247](https://github.com/user-attachments/assets/f435baa5-8731-49ea-a982-b45d19bc04de)

**default server (working)**
![Screenshot 2024-11-26 130113](https://github.com/user-attachments/assets/bdf23f52-7685-4ace-bcc3-4c48e29816ea)

As you can see it doesn't get the query params on httpx or httpbeast.


Fix patch:
diff --git a/src/happyx/ssr/server.nim b/src/happyx/ssr/server.nim
index 2d46ff50..6885a181 100755
--- a/src/happyx/ssr/server.nim
+++ b/src/happyx/ssr/server.nim
@@ -821,7 +821,7 @@ macro routes*(server: Server, body: untyped = newStmtList()): untyped =
           ident"queryRaw"
         else:
           newStmtList(
-            newLetStmt(val, newCall("split", ident"urlPath", newLit"?")),
+            newLetStmt(val, newCall("split", newCall("decodeUrl", newCall("get", newCall("path", ident"req"))), newLit"?")),
             newNimNode(nnkIfStmt).add(
               newNimNode(nnkElifBranch).add(
                 newCall(">=", newCall("len", val), newLit(2)),


Test patch:
diff --git a/tests/testc5.nim b/tests/testc5.nim
index eab17107..95c346c7 100644
--- a/tests/testc5.nim
+++ b/tests/testc5.nim
@@ -27,3 +27,9 @@ serve("127.0.0.1", 5000):
       "age": myModel.age,
       "data": myModel.data
     }}
+  
+  get "/get":
+    echo query  # StringTableRef
+    echo urlPath  # string
+    echo query?id  # string
+    return query?id