手順
- RestClient 拡張をインストールしておく
- VsCode でテキストエディタに以下のように書いて、コマンドパレットで Generate Code Snippet を選ぶ
POST https://httpbin.org/post HTTP/1.1
Content-Type: application/json
{
"foo": "bar",
"wow": "yeah"
}
生成の例
require 'uri'
require 'net/http'
require 'openssl'
url = URI("https://httpbin.org/post")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
request = Net::HTTP::Post.new(url)
request["content-type"] = 'application/json'
request.body = "{\"foo\": \"bar\",\"wow\": \"yeah\"}"
response = http.request(request)
puts response.read_body
curl のコマンドを生成する
こちらもコマンドで可能。
クリップボードにコピーされるので、ペーストすればコマンドになる。
curl --request POST \
--url https://httpbin.org/post \
--header 'content-type: application/json' \
--data '{"foo": "bar","wow": "yeah"}'
参考
VS Code上でHTTPリクエストを送信し、VS Code上でレスポンスを確認できる「REST Client」拡張の紹介 - Qiita
Original by Github issue
チャットメンバー募集
何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。