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. Buf Studio is an interactive web UI for all your Protobuf services stored on the Buf Schema Registry.