SlideShare a Scribd company logo
Intuitive CLIs for gRPC APIs
Noah Dietz
(@no_d_here)
curl https://my.api.net/post 
-H "Content-Type: application/json" 
-d '{"requird": "field"}'
curl https://my.api.net/post 
-H "Content-Type: application/json" 
-d '{"required": "field"}'
What it feels like today
Web Interface Command-line API
Perfect World
Web Interface Command-line API
Likely Reality
Web Interface Command-line APIAPI
Q: Why do we care about command line
consumption?
A: It’s a gateway for new developers and
consumers
Q: How can we improve the command line
API consumption experience?
A: Use structured definitions to intuitively
represent the interface
Protocol Buffers
Code-gen
Source
Protocol Buffers
IDL (Interface definition language)
Describe once and generate interfaces for any
language.
Data Model
Structure of the request and response.
Wire Format
Binary format for network transmission.
service RouteGuide {
rpc GetFeature(Point) returns (Feature);
rpc RouteChat(stream RouteNote) returns (stream RouteNote);
}
message Point {
int32 latitude = 1;
int32 longitude = 2;
}
message Feature {
string name = 1;
Point location = 2;
}
message RouteNote {
Point location = 1;
string message = 2;
}
C/C++
Java is a registered trademark of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
Cutting edge transport
Bespoke wire format
Consumed via generated code
How from CLI?!
State of the Art
● Server reflection-based CLIs
○ Similar to HTTP cURL
○ Favors flexibility over API
consumption experience
● github.com/grpc/grpc/.../grpc_cli
● github.com/fullstorydev/grpcurl
#grpcurl example
# listing available Services
> grpcurl my.api.net list
MyService
# listing Service RPCs
> grpccurl my.api.net list MyService
MethodA
MethodB
# describing specific Service RPC
> grpcurl my.api.net describe MyService MethodA
…
# describing specific Message
> grpcurl my.api.net describe MethodAInput
…
# invoking a Service RPC
> grpcurl -d '{"name": "Jane Doe"}' 
my.api.net 
MyService.MethodA
…
Handwritten CLIs?
Intuitive CLIs for gRPC APIs
github.com/googleapis/kiosk
“Why wasn’t this CLI generated?”
- @timburks
Intuitive CLIs for gRPC APIs
@no_d_here
Generated
Command Line
Interfaces
Generated Command Line Interfaces (gcli)
● Go lang
● Cobra CLI framework
● Uses Google generated API clients (GAPIC)
● github.com/googleapis/gapic-generator-go
Goals
● Generate a CLI tailored to a given gRPC
API
● Generate a more human-oriented
interface
● Unified experience across consumption
mediums
Non-Goals
● Provide a single, generic utility that can
invoke any gRPC API
● Replace gcloud SDK as the canonical
Google Cloud CLI
Generate a CLI tailored to
a given gRPC API
API Description → Command Structure
kctl display list-kiosks
Root command Service name Method name
API Description → Command Structure
$ kctl display
Top level command for Service: Display
Usage:
kctl display [command]
Available Commands:
create-kiosk
create-sign
delete-kiosk
delete-sign
get-kiosk
get-sign
list-kiosks
list-signs
...
Payload construction: Primitives
kctl display get-sign --id=<int32>
Field name Field type
kctl ... --kiosk_ids=<int32> --kiosk_ids=<int32>
Repeated field name Repeated field type
Payload construction: Repeated Primitives
kctl ... --size.width=<int32> --size.height=<int32>
Nested
field’s
name
Nested
message
field
name
Nested
message
field
type
Payload construction: Nested Messages
“Correct by construction”
- @timburks
Generate a more
human-oriented interface
Making machine things human: LRO
kctl display cycle-kiosks --id=123 --follow
Wait for LRO
to finish
kctl display cycle-kiosks-poll --operation=<id>
Operation IDExtra polling
helper
Making machine things human: Streaming
● stdin OR
--from_file=<path>
○ JSON Protobuf format
● stdout OR
--out_file=<path>
# JSON Protobuf input format
{"field": "a"}
{"field": "b"}
{"field": "c"}
{"field": "d"}
Unified experience
across consumption
mediums
Educate the consumer: --help
$ kctl display create-sign --help
Create a sign. This enrolls the sign for sign display.
Usage:
kctl display create-sign [flags]
Flags:
--from_file string Absolute path to JSON file containing request payload
-h, --help help for create-sign
--image bytesHex Data of image currently displayed on sign
--name string Required. Name of the sign
--text string Text to display on sign
...
Educate the consumer: bash autocompletion
$ kctl completion --help
Enable bash completion like so:
Linux:
source <(kctl completion)
Mac:
brew install bash-completion
kctl completion > $(brew --prefix)/etc/bash_completion.d/kctl
Usage:
kctl completion [flags]
Flags:
-h, --help help for completion
kctl/
create-kiosk.go
delete-sign.go
get-sign.go
list-kiosks.go
create-sign.go
display_service.go
list-signs.go
delete-kiosk.go
get-kiosk.go
root.go
Educate the consumer: code & structure
Service command
root command
Method command
# Input message to generated usage
message CreateKioskRequest →
var CreateKioskInput *pb.CreateKioskRequest
# RPC to generated cmd to usage
rpc CreateKiosk → var createKioskCmd →
kctl display create-kiosk
@no_d_here
Demo
@no_d_here
When a CLI won’t
help
Large, nested payloads
--consistency_selector.new_transaction.mode.read_only.consistency_selector.read_time.seconds
--consistency_selector.new_transaction.mode.read_only.consistency_selector.read_time.nanos
firestore.Firestore.BatchGetDocuments
dataproc.WorkflowTemplateService.CreateWorkflowTemplate
● Had > 50 flags
● Deeply nested fields
Unstructured “structured” APIs
curl https://my.api.net/post 
-H "Content-Type: application/json" 
-d '{"sql": "SELECT * FROM foo;"}'
@no_d_here
All this to say...
Wrapping it up
● CLI API consumption is a gateway & important tool
● Structured API definitions should guide the CLI experience
● Educate the consumer at every opportunity
● Not every API is meant for the command line
Thank you
Noah Dietz
(@no_d_here)

More Related Content

PDF
Introduction to Cappuccino
PPTX
Introduction to C Programming by Subid Biswas
PDF
Getting Swifty in an Objective-C World
PDF
Ballerina Serverless with Kubeless
PDF
MCE^3 - Kyle Fuller - End-to-end Building Web Services in-swift-mce-2016
PPTX
Automate_LSF_ppt_final
PPTX
10 minute command line apps with zio cli
PDF
用 OPENRNDR 將 Chatbot 訊息視覺化
Introduction to Cappuccino
Introduction to C Programming by Subid Biswas
Getting Swifty in an Objective-C World
Ballerina Serverless with Kubeless
MCE^3 - Kyle Fuller - End-to-end Building Web Services in-swift-mce-2016
Automate_LSF_ppt_final
10 minute command line apps with zio cli
用 OPENRNDR 將 Chatbot 訊息視覺化

Similar to Intuitive CLIs for gRPC APIs (20)

PDF
Intuitive CLIs for gRPC - GoSV Jan '19
PDF
GDG Devfest 2019 - Build go kit microservices at kubernetes with ease
PDF
如何透過 Go-kit 快速搭建微服務架構應用程式實戰
PDF
Usable APIs at Scale
PDF
GDG Cloud Taipei meetup #50 - Build go kit microservices at kubernetes with ...
PDF
Driving containerd operations with gRPC
PDF
No REST for the Wicked: REST and Catalyst
PPTX
Mcroservices with docker kubernetes, goang and grpc, overview
PPTX
CocoaConf: The Language of Mobile Software is APIs
PDF
Deploy and Secure Your API Gateway with NGINX: From Zero to Hero – APCJ
PDF
How to build and distribute CLI tool in 15 minutes with Golang
PPTX
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
PPTX
Provisioning Heterogenous Bare Metal with Stacki
PDF
Ingress? That’s So 2020! Introducing the Kubernetes Gateway API
PDF
Zero to scaleable in ten minutes
PDF
Ingress? That’s So 2020! Introducing the Kubernetes Gateway API
PDF
RESTful Services and Distributed OSGi - 04/2009
PDF
Building REST APIs using gRPC and Go
PPTX
Kubernetes Ingress to Service Mesh (and beyond!)
PDF
Microservices in GO - Massimiliano Dessì - Codemotion Rome 2017
Intuitive CLIs for gRPC - GoSV Jan '19
GDG Devfest 2019 - Build go kit microservices at kubernetes with ease
如何透過 Go-kit 快速搭建微服務架構應用程式實戰
Usable APIs at Scale
GDG Cloud Taipei meetup #50 - Build go kit microservices at kubernetes with ...
Driving containerd operations with gRPC
No REST for the Wicked: REST and Catalyst
Mcroservices with docker kubernetes, goang and grpc, overview
CocoaConf: The Language of Mobile Software is APIs
Deploy and Secure Your API Gateway with NGINX: From Zero to Hero – APCJ
How to build and distribute CLI tool in 15 minutes with Golang
Session: A Reference Architecture for Running Modern APIs with NGINX Unit and...
Provisioning Heterogenous Bare Metal with Stacki
Ingress? That’s So 2020! Introducing the Kubernetes Gateway API
Zero to scaleable in ten minutes
Ingress? That’s So 2020! Introducing the Kubernetes Gateway API
RESTful Services and Distributed OSGi - 04/2009
Building REST APIs using gRPC and Go
Kubernetes Ingress to Service Mesh (and beyond!)
Microservices in GO - Massimiliano Dessì - Codemotion Rome 2017
Ad

More from Nordic APIs (20)

PPTX
How to Choose the Right API Platform - We Have the Tool You Need! - Mikkel Iv...
PPTX
Bulletproof Backend Architecture: Building Adaptive Services with Self-Descri...
PDF
Implementing Zero Trust Security in API Gateway with Cilium - Pubudu Gunatila...
PPTX
Event-Driven Architecture the Cloud-Native Way - Manuel Ottlik, HDI Global SE
PPTX
Navigating the Post-OpenAPI Era with Innovative API Design Frameworks - Danie...
PDF
Using Typespec for Open Finance Standards - Chris Wood, Ozone API
PPTX
Schema-first API Design Using Typespec - Cailin Smith, Microsoft
PPTX
Avoiding APIpocalypse; API Resiliency Testing FTW! - Naresh Jain, Xnsio
PPTX
How to Build an Integration Platform with Open Source - Magnus Hedner, Benify
PPTX
API Design First in Practise – An Experience Report - Hari Krishnan, Specmatic
PPTX
The Right Kind of API – How To Choose Appropriate API Protocols and Data Form...
PPTX
Why Frequent API Hackathons Are Key to Product Market Feedback and Go-to-Mark...
PPTX
Maximizing API Management Efficiency: The Power of Shifting Down with APIOps ...
PPTX
APIs Vs Events - Bala Bairapaka, Sandvik AB
PPTX
GraphQL in the Post-Hype Era - Daniel Hervas, Reckon Digital
PPTX
From Good API Design to Secure Design - Axel Grosse, 42Crunch
PPTX
API Revolution in IoT: How Platform Engineering Streamlines API Development -...
PPTX
Unlocking the ROI of API Platforms: What Success Actually Looks Like - Budhad...
PDF
Increase Your Productivity with No-Code GraphQL Mocking - Hugo Guerrero, Red Hat
PPTX
Securely Boosting Any Product with Generative AI APIs - Ruben Sitbon, Theodo ...
How to Choose the Right API Platform - We Have the Tool You Need! - Mikkel Iv...
Bulletproof Backend Architecture: Building Adaptive Services with Self-Descri...
Implementing Zero Trust Security in API Gateway with Cilium - Pubudu Gunatila...
Event-Driven Architecture the Cloud-Native Way - Manuel Ottlik, HDI Global SE
Navigating the Post-OpenAPI Era with Innovative API Design Frameworks - Danie...
Using Typespec for Open Finance Standards - Chris Wood, Ozone API
Schema-first API Design Using Typespec - Cailin Smith, Microsoft
Avoiding APIpocalypse; API Resiliency Testing FTW! - Naresh Jain, Xnsio
How to Build an Integration Platform with Open Source - Magnus Hedner, Benify
API Design First in Practise – An Experience Report - Hari Krishnan, Specmatic
The Right Kind of API – How To Choose Appropriate API Protocols and Data Form...
Why Frequent API Hackathons Are Key to Product Market Feedback and Go-to-Mark...
Maximizing API Management Efficiency: The Power of Shifting Down with APIOps ...
APIs Vs Events - Bala Bairapaka, Sandvik AB
GraphQL in the Post-Hype Era - Daniel Hervas, Reckon Digital
From Good API Design to Secure Design - Axel Grosse, 42Crunch
API Revolution in IoT: How Platform Engineering Streamlines API Development -...
Unlocking the ROI of API Platforms: What Success Actually Looks Like - Budhad...
Increase Your Productivity with No-Code GraphQL Mocking - Hugo Guerrero, Red Hat
Securely Boosting Any Product with Generative AI APIs - Ruben Sitbon, Theodo ...
Ad

Recently uploaded (20)

PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PPTX
Cloud computing and distributed systems.
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Big Data Technologies - Introduction.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
MYSQL Presentation for SQL database connectivity
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
20250228 LYD VKU AI Blended-Learning.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
The Rise and Fall of 3GPP – Time for a Sabbatical?
Cloud computing and distributed systems.
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Mobile App Security Testing_ A Comprehensive Guide.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Per capita expenditure prediction using model stacking based on satellite ima...
Diabetes mellitus diagnosis method based random forest with bat algorithm
“AI and Expert System Decision Support & Business Intelligence Systems”
MIND Revenue Release Quarter 2 2025 Press Release
Big Data Technologies - Introduction.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
The AUB Centre for AI in Media Proposal.docx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Encapsulation_ Review paper, used for researhc scholars
MYSQL Presentation for SQL database connectivity
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf

Intuitive CLIs for gRPC APIs