Skip to content

GraphQL, REST, gRPC, and Connect — all powered from the same underlying Protobuf API — thanks to Buf and Tailcall

Notifications You must be signed in to change notification settings

kevinmichaelchen/buf-vanguard-rest

Repository files navigation

buf-vanguard-rest

A demo showing how one Buf API can offer GraphQL, REST, gRPC, and Connect protocols, using a combination of Vanguard and Tailcall.

Inspired by this example.

Getting Started

Run the server

Run the server on port 8080 with:

go run main.go

Make a REST request

$ http localhost:8080/foos/1

HTTP/1.1 200 OK
Accept-Encoding: gzip
Content-Encoding: gzip
Content-Length: 55
Content-Type: application/json
Date: Sat, 13 Jan 2024 18:28:44 GMT

{
    "foo": {
        "id": "1",
        "name": "Bar"
    }
}

Make a Connect request

curl -v http://localhost:8080/bvr.v1beta1.FooService/CreateFoo \
  -H "Content-Type: application/json" \
  --data-binary @- <<EOF
  {
    "name": "BAR"
  }
EOF

or

pkgx http http://localhost:8080/bvr.v1beta1.FooService/CreateFoo name="BAR"

Make a GraphQL request

Thanks to Tailcall, we've able to generate a GraphQL API from our Vanguard HTTP APIs. (See tailcall.graphql).

Once you've started the Tailcall server with:

pkgx tailcall start ./tailcall.graphql

You can visit the GraphQL Playground and run the following query:

{
  foo(input: { id: "1" }) {
    foo {
      id
      name
    }
  }
}

About

GraphQL, REST, gRPC, and Connect — all powered from the same underlying Protobuf API — thanks to Buf and Tailcall

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages