TL;DR

gRPC サーバにリクエストを送る Buf CLI のコマンド。gRPC だけでなく、gRPC Web と Connect のプロトコルにも対応している。

仕組み

使うプロトコルは --protocol で指定する。gRPC には HTTP/2 が必要だが、--http2-prior-knowledge がないと HTTP/1.1 が使われるので、HTTPS でない URL に gRPC で送るときはこのフラグも付ける。

例

$ buf curl --http2-prior-knowledge --protocol grpc \
  http://localhost:8080/radish.weather.v1.WeatherService/GetWeather

注意点

--http2-prior-knowledge を付けずに http の URL へ gRPC で送ると、次のエラーになる。

Failure: grpc protocol cannot be used with plain-text URLs (http)
unless --http2-prior-knowledge flag is set

サーバが Reflection API に対応していないと、次のエラーになる。

Failure: failed to resolve symbol "radish.weather.v1.WeatherService": unimplemented: HTTP status 404 Not Found

自分の理解

Connect なら curl でも呼べるのでは、と思った。プロトコルごとにツールを使い分けなくてよいのが利点なのかもしれない。

関連

出典