RPC: post or get and how is the payload handled?

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",

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.

RPC functions absolutely support both GET and POST, the server does not expect you to send a request body along with a GET request.

Nakama does not explicitly log incoming RPC payloads, what you’re seeing is an error caused by invalid input. You can see curl examples of RPC function calls in the docs.

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.

1 Like

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.