RPC using REST or GET

Hi all,
I try to figure out, how the RPC (using ‘curl’) really works. I found some documentation under ‘https://mongoose-os.com/docs/mongoose-os/userguide/rpc.md’ and implemented the example, i.e. the RPC-Function ‘Sum’.
Then I tried the given examples:
REST:

Has anybody an idea, why the original calls from the example do not work but just one slightly adapted one does?

Thanks for any inputs and
Kind regards
Rolf

The particulars on how to pass the parameters to the client of your choice running on the command interpreter of your choice are… particular.

‘-d’ in curl is an option to send using POST. If you send with curl via POST, you have to send a JSON object. Generally, that JSON object will be stringified. You need to pass the object after the -d as a single block; that will depend on how your shell will separate parameters and whether it likes or not the single quotes '. What you did was to avoid both the single quotes and the space that was there because otherwise that space will break the object in most environments. It works as is in my system.

If you put the parameters along with the URL you are using GET and here instead of sending a JSON object you will send parameters the GET way. So, different parameters have to be separated with the ampersand sign &.
Some command interpreters have a special meaning for this sign, so, it is common to use single quotes to escape the sequence and so the shell does not interpret it. The example works on my system if I use double quotes instead of single quotes.

BTW, my shell is bash

Personally I’ve found mDash a really nice place to test RPC as it formats it correctly for you and even gives you the curl commands it you want to perform the commands from command line

rpc-common latest accepts GET requests.

I’ve included rpc-common however I’m getting JSON errors when I use http get

eg
curl "http://192.168.0.123/rpc/relay?name=RELAY1&cmd=SWITCH"

[Jul 24 13:29:24.395] mg_rpc.c:309            relay via HTTP 192.168.0.10:57054
[Jul 24 13:29:24.395]   at api_rpc.js:10
[Jul 24 13:29:24.395] MJS callback error: invalid JSON string

Assuming the arguments format is {name:%Q,cmd:%Q},
the request string should be relay?name=%22RELAY1%22&cmd=%22SWITCH%22

See the example here.