添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
没读研的猴子  ·  Unable to setup SFTP ...·  3 天前    · 
温文尔雅的生姜  ·  How to install ...·  3 天前    · 
仗义的凉茶  ·  Curl command is not ...·  3 天前    · 
卖萌的滑板  ·  Openwrt Error ...·  3 天前    · 
乖乖的树叶  ·  The Ultimate ...·  2 月前    · 
气势凌人的仙人掌  ·  Can't compile ...·  4 月前    · 
Skip to main content

cURL & other clients

Not every client has access to generated code and a full RPC framework: perhaps you're debugging in a bare-bones environment, or perhaps your clients are using a language or framework without good RPC bindings. Connect shines in these circumstances: we designed the Connect protocol to make unary RPCs work well with even the simplest HTTP/1.1 clients. (Of course, you can also call Connect APIs using any gRPC or gRPC-Web client.)

cURL

Connect handlers automatically support JSON. Because the Connect protocol also uses standard HTTP headers for unary RPCs, calling your API is a cURL one-liner:

$ curl --header "Content-Type: application/json" \
--data '{"sentence": "I feel happy."}' \
https://demo.connectrpc.com/connectrpc.eliza.v1.ElizaService/Say

The response is:

{"sentence": "Feeling happy? Tell me more."}

The demo service is live you're welcome to give that command a try! You can also use --verbose to see all the response headers or --http1.1 to prevent upgrading to HTTP/2.

You can make the same call with HTTP GET, where the request message is encoded in a query parameter:

$ curl --get --data-urlencode 'encoding=json' \
--data-urlencode 'message={"sentence": "I feel happy."}' \
https://demo.connectrpc.com/connectrpc.eliza.v1.ElizaService/Say

You can also visit this URL in your browser. Unary RPCs can opt in to support HTTP GET with an option. For details, take a look at the blog post introducing the feature, and at the protocol specification for Connect.

fetch API

We recommend @connectrpc/connect-web so that the compiler can type-check your code, but browsers can easily make unary calls to Connect APIs with just the fetch API. Right in your developer tools, try this:

fetch("https://demo.connectrpc.com/connectrpc.eliza.v1.ElizaService/Say", {
"method": "POST",
"headers": {"Content-Type": "application/json"},
"body": JSON.stringify({"sentence": "I feel happy."})
})
.then(response => { return response.json() })
.then(data => { console.log(data) })

The same call with HTTP GET:

const url = new URL("https://demo.connectrpc.com/connectrpc.eliza.v1.ElizaService/Say");
url.searchParams.set("encoding", "json");
url.searchParams.set("message", JSON.stringify({"sentence": "I feel happy."}));
fetch(url)
.then(response => { return response.json() })
.then(data => { console.log(data) })

Buf Studio

If you prefer a graphical user interface to explore an API, take a look at Buf Studio .