gRPC Documentation Generators | Top 4 tools
gRPC is great when it goes to communication between services. It has many built-in mechanisms to speed up the development process, like auto-generating SDK or streaming support. Seems to be the perfect choice for building your API, right? But in the real world, there are not many public gRPC APIs. REST is still the king. Most gRPC backends expose only the REST API.
The main problem is that gRPC is hard. It is hard to start, it is hard to play with, and even hard to debug. The typical solution for that is to use the REST-to-gRPC translation proxy, like grpc-gateway. That’s not a perfect solution because it complicates the architecture, increases the latency and the maintenance costs.
In this post, I’ll compare a few gRPC documentation generators that can help you mitigate those problems. Let’s create a truly gRPC API documentation!
gRPC-docs
gRPC Docs is an open-source project. The main goal is to deliver a Swagger-UI-like experience for gRPC API. It might be self-hosted or styled in any manner you like. Check the demo.
Setup self-served (4 minutes)
- Install
protoc-gen-doc
withgo get -u github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc
or with docker. - Generate the JSON API description with command
protoc --doc_out=./ --doc_opt=json,description.json -I your-proto-root your-proto-files
- Inside your react project (if you don’t have one, clone the repository
git clone https://github.com/gendocu-com/grpc-docs
and go toexample
directory) add the library -npm install --save grpc-docs
. - Copy the
description.json
file from the 2nd step to thepublic
directory in the project - Instantiate the
grpc-docs
widget with the path to thedescription.json
file, e.g., for a file located inpublic/example-descriptors/library-app.json
:
import React from 'react'
import { GRPCSelfGeneratedAPIReference } from 'grpc-docs'
import 'grpc-docs/dist/index.css'
const App = () => {
return <GRPCSelfGeneratedAPIReference file='/example-descriptors/library-app.json' scheme='/example-descriptors/library-app-apispec.yaml' />
}
export default App
Summary
Pros:
- Free and open-sourced
- Quick setup - no tools or config files are required to start
- Easy to override/create own style
- Easy to embed within existing documentation tool
- Ready-to-copy gRPC Curl queries with the setup steps - similar to
curl
command for REST API
Cons:
- Try it out only with the GenDocu Cloud project (gRPC is not supported directly in browsers)
- For code-snippets and SDKs requires GenDocu Cloud project
- No built-in support for private documentation - the only way is to restrict it directly on your hosting
gRPC Developer Portal (GenDocu Cloud)
GenDocu Cloud is CI/CD solution to build and deliver the gRPC. It automatically subscribes to all the new commits via GitHub and rebuilds the documentation and SDKs. It also generates the SDKs and code-snippets for six programming languages. It also handles the gRPC Web SDK generation. It is possible to define the example values for message structures and authentication schemes. You can also call the endpoints from documentation like in Swagger UI. Check full documentation demo or API Reference demo to explore all the features.
Setup (1 minute)
It’s cloud solution, so no additional setup is required.
- Login to GenDocu Cloud
- Create a new project - select the gRPC source directly from your GitHub repository.
- Visit the result documentation page
Summary
Pros:
- Free private and public docs for individuals and small teams
- Open-source based product -
grpc-docs
- Quick setup - no tools or config files are required to start
- Integrated CI/CD for gRPC with linter
- Generates the SDK for 4 gRPC technologies (Golang, Java, C#, Python) and 2 gRPC Web (Javascript, Typescript)
- Generates the code snippets for each endpoint
- Call endpoints directly from browser
- RBAC support
- Easy to customize with built-in editor
- Embeddable as an HTML widget
Cons:
- No self-hosted option
- Supports only GitHub
- Requires to provide the raw Protobuf files from repository
Buf
One of the most popular gRPC tools is the buf
CLI - it extends the features known from prototool
.
The Buf company has created a superb tool and integrated it with its own API Schema Registry.
Every schema has its documentation - an example can be found here, here or here.
Setup (4 minutes)
- Install the Buf CLI
- Authorize the Buf CLI with
buf registry login
- Create a repository on the buf.build webpage
- Create a configuration file
buf config init
and reference the repository - thebuf.build/
- Use command
build push
to create a scheme in the Buf’s registry.
Summary
Buf is not a documentation tool. Nevertheless, it provides decent documentation for your gRPC API.
Pros:
- Installation steps for Golang. You can also create your template for other languages.
- Documentation is nice and clean
- RBAC support
Cons:
- Paid for private documentation
- You have to install and configure the CLI tool before proceeding
- You have to build the packages locally or configure your CI/CD
- Buf is an early startup - the pricing and business model are still unknown
- There is no way of defining example values for the structure
- Try it out feature missing
- There is no way of customization documentation
- No self-hosted option
protoc-gen-doc
There is also a great, open-source project - protoc-gen-doc
.
It is free and generates the documentation in Markdown, HTML, or JSON. Sadly, it is a protobuf documentation tool - not gRPC.
It generates the description of the protobuf structure without even mentioning the gRPC services and methods.
Setup (2 minutes)
- Install it with
go get -u github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc
. It is also possible to use dockerized version - more here. - Invoke the plugin
protoc --doc-opt=html,docs.html <your-protos>
- Open
docs.html
file
Summary
It is a good starter for the project - it can be easily adjusted/replaced.
Pros:
- Free and opensource
- Easy to start
- Fast and easy to embed in any existing webpage - static HTML
- Easy to style - the markdown format or custom template
Cons:
- Documentation for the data structures only (protobuf, not gRPC)
- Lack of SDK or code generation support
- Lack of example values for the structures
- Have to manage custom hosting
- Have to manage the access to the documentation on your own
Comparison summary
protoc-gen-doc
is fine for internal documentation - it is easiest to set up, but it doesn’t generate the gRPC documentation. You have to host it on your own. It is the only self-hosted option.
GenDocu Cloud is the best to start with as it provides CI/CD out of the box - you can set it up in a minute and requires no maintenance. Great for public and private gRPC API documentation.
Buf is the only GenDocu alternative when it goes to public, hosted, gRPC API documentation.
If you find anything missing, please let us know at support[at]gendocu.com
Develop gRPC API 10x faster
- 1 minute to setup
- Direct integration with GitHub
- Autogenerate gRPC and gRPC-Web SDK
- Live-interact with gRPC endpoints