[dev] JSON-RPC の学習、steemCreated with Sketch.

in #japanese3 years ago

こんにちは、@yasuです。

ChatGPTにソースコードの作成をお願いしてみました。
https://openai.com/blog/chatgpt

そのソースの完成度には、本当にびっくりしました。

その後、少し手を加えました。

3種類の関数を追加しました。
・add 引数を配列で渡して、引数を合計する
・join 引数を配列で渡して、引数を文字列として連結する
・json 引数をJSON形式で渡す

工夫したところ、ヘッダーを付けた。
--header 'Content-Type: application/json'

ソース

image.png

add

curl --header 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"add","params":[2,3,5],"id":1}' http://localhost:3000
image.png

サーバ側のログ
image.png

結果
{"jsonrpc":"2.0","result":10,"id":1}

join

curl --header 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"join","params":[2,3,5],"id":1}' http://localhost:3000
image.png

サーバ側のログ
image.png

結果
{"jsonrpc":"2.0","result":"2---3---5","id":1}

json

curl --header 'Content-Type: application/json' --data '{"jsonrpc":"2.0","method":"json","params":{"a":123},"id":1}' http://localhost:3000
image.png

サーバ側のログ
image.png

結果
{"jsonrpc":"2.0","result":123,"id":1}

Coin Marketplace

STEEM 0.04
TRX 0.33
JST 0.093
BTC 63802.98
ETH 1793.00
USDT 1.00
SBD 0.39