substrate-docs icon indicating copy to clipboard operation
substrate-docs copied to clipboard

Deprecate all `curl` usage in docs examples

Open nuke-web3 opened this issue 3 years ago • 0 comments

Is there an existing issue?

  • [X] I have searched the existing issues

Experiencing problems? Have you tried our Stack Exchange first?

  • [X] This is not a support question.

Content request

The HTML server in substrate may be depricated & removed, as it's not widely used. See discussion here for insights.

An alternative to curl that relies on this is https://github.com/vi/websocat - a rust based Netcat, curl and socat for [WebSockets](https://en.wikipedia.org/wiki/WebSocket).

Here is an example using rpc.polkadot.io and localhost:9944 as an endpoint:

# basic usage
echo '{"id":1,"jsonrpc":"2.0","method":"chain_getBlock","params":[]}' | websocat -n1 -B 99999999 wss://rpc.polkadot.io
echo '{"id":1,"jsonrpc":"2.0","method":"chain_getBlock","params":[]}' | websocat -n1 -B 99999999 ws://127.0.0.1:9944

# bash input without echo & pipes
websocat -n1 -B 99999999 wss://rpc.polkadot.io <<< '{"id":1,"jsonrpc":"2.0","method":"chain_getBlock","params":[]}'
websocat -n1 -B 99999999 ws://127.0.0.1:9944 <<< '{"id":1,"jsonrpc":"2.0","method":"chain_getBlock","params":[]}'

# jq is optional parser to make the terminal output very nice
echo '{"id":1,"jsonrpc":"2.0","method":"chain_getBlock","params":[]}' | websocat -n1 -B 99999999 wss://rpc.polkadot.io | jq .result
echo '{"id":1,"jsonrpc":"2.0","method":"chain_getBlock","params":[]}' | websocat -n1 -B 99999999 ws://127.0.0.1:9944 | jq .result

Alternatives:

https://www.npmjs.com/package/wscat

Are you willing to help with this request?

Yes!

nuke-web3 avatar Sep 15 '22 20:09 nuke-web3