I have a couple of simple RPC functions registered in a Go module. They work fine and return data when called. What they have in common though is that they don’t accept any parameters or other data. I’m at a loss as to how that is supposed to work.
The signature of my function is the normal:
func myStuff(ctx context.Context, logger runtime.Logger, db *sql.DB, nk runtime.NakamaModule, payload string) (string, error) {
...
}
But whatever I do, the payload is empty. The RPC calls are using HTTP GET calls, but passing a body in a GET call is not really something that’s encouraged. But I’ve tried adding a body, but that doesn’t seem to get delivered. Adding parameters to the URL like: /v2/rpc/myStuff?id=foo also doesn’t work and payload is empty.
If I try a POST I see that my function is not called and Nakama returns an error:
{
"error":"json: cannot unmarshal object into Go value of type string",
"message":"json: cannot unmarshal object into Go value of type string",
"code":3
}
What does this mean? Does the server log what it received somewhere? I’m running with debug logging turned on. Or is this a case where the server does own broken JSON validation somehow?
Hm, also, does anyone read these forums? I seem to be pretty alone here.
Note especially the escaping of payloads, but you will likely want to set the unwrap=true query parameter to allow you to send arbitrary unescaped data as the RPC payload.
I read that part, but it talks about server to server communication so I didn’t think it was applicable. Adding unwrap to my URL seems to be the thing.
A short mention in the docs about POST and GET would be nice though, now it’s mostly up to trial and error.
“both GET and POST” - i think this is not (no longer?) correct. I try to access a RPC via GET and it does not work.
I use the nakama-js library and there is the “rpcHttpKey” function that internally uses the “rpcFunc2” function that makes a GET call and i’m not sure why it would, because when a session-token is used, it makes a POST call (and that works fine!).
The “payload” query param seems to be ignored in the GET case, making httpkey-requests totally pointless and the library actually useless. I may be doing something wrong, but i can’t find any hint in the documentation.
@dela I believe it is part of the HTTP spec that GET requests should not contain a body but query params only, so even if the request contains one, the server will ignore it.