SlideShare a Scribd company logo
Implementing OpenAPI and
GraphQL Services with gRPC
Tim Burks (timburks@google.com, @timburks)
1. API technologies: OpenAPI, GraphQL, gRPC
2. Why implement your API with gRPC?
3. Implementing OpenAPI services with gRPC
4. Implementing GraphQL services with gRPC
Topics
1
API Technologies:
OpenAPI, GraphQL,
gRPC
Five Questions about API Systems
1. What problem is this API system addressing?
2. How are APIs called?
3. How are APIs built?
4. What’s great about this?
5. What’s challenging about this?
What problem is OpenAPI addressing?
“The OpenAPI Specification, originally known
as the Swagger Specification, is a specification
for machine-readable interface files for
describing, producing, consuming, and
visualizing RESTful web services.”
Wikipedia
How an OpenAPI service is called:
You might call it from your browser.
In your applications, you call it from code.
openapi-generator
autorest
APIMatic
SwagGen (Swift)
Paperclip (Rust)
How an OpenAPI service is built:
🤞 Code-first
Handwritten implementations.
Handwritten API descriptions.
⚙ Code-first (better)
Handwritten implementations. API
descriptions generated from code.
📐 Spec-first
Handwritten API descriptions.
Implementations generated from API descriptions.
What’s great about OpenAPI:
● Standards and tools make it easy to get
started.
○ HTTP
○ JSON/YAML
● Very popular - large community.
What’s challenging about OpenAPI:
“Unfortunately, many of the APIs that claim to be
RESTful layer a lot of proprietary concepts on top
of HTTP. Essentially, they invent their own API and
use HTTP as a lower-level transport layer, rather
than using HTTP directly as it was designed. In fact,
there’s so much variability in the way that
people use the term REST in the context of APIs
that it’s difficult to know what they mean by it
unless you know them well.”
Martin Nally
What problem is GraphQL addressing?
“GraphQL is a query language for APIs and a
runtime for fulfilling those queries with your
existing data. GraphQL provides a complete
and understandable description of the data in
your API, gives clients the power to ask for
exactly what they need and nothing more,
makes it easier to evolve APIs over time, and
enables powerful developer tools.”
graphql.org
How a GraphQL service is called:
“With express-graphql, you can just send an
HTTP POST request to the endpoint you
mounted your GraphQL server on, passing the
GraphQL query as the query field in a JSON
payload.”
https://graphql.org/graphql-js/graphql-clients/
Also GraphiQL!
How a GraphQL service is built:
● Code-first, schema extracted from code
● Schema-first - code generated from SDL
● Generated from underlying APIs
○ Federated from other GraphQL APIs
○ OpenAPI-to-GraphQL
○ rejoiner
What’s great about GraphQL:
● Simple client-side interface
● Optimizes for client performance
● Layered on familiar technology
● Sharable BFF
What’s challenging about GraphQL:
● Complex implementation
● Performance challenges
● Versioning
● Schema design
Public GraphQL APIs are rare.
What problem is gRPC addressing?
“gRPC is a modern open source high
performance RPC framework that can run in
any environment. It can efficiently connect
services in and across data centers with
pluggable support for load balancing, tracing,
health checking and authentication. It is also
applicable in last mile of distributed computing
to connect devices, mobile applications and
browsers to backend services.”
grpc.io
How a gRPC service is called:
ALWAYS specification-first.
Clients are generated from API
descriptions written in the Protocol Buffer
language.
How a gRPC service is built:
ALWAYS specification-first.
Service code is generated. Typically this
generated code declares an interface that is
implemented in language-native data
structures and patterns.
What’s great about gRPC:
So much is built-in.
High performance.
Cross-language compatibility.
Potential for very nice client integration.
What’s challenging about gRPC:
Some learning and tooling is required!
2
Why implement
your API with
gRPC?
gRPC APIs have a native language.
Protocol Buffers
Protocol Buffers is a language-neutral, platform-neutral, extensible
mechanism for serializing structured data.
“Protocol Buffers” means several things
1. A serialization mechanism
2. An interface description language
3. A methodology
Protocol Buffer Serialization
A message is just a stream of bytes
[field_number<<3 + wire_type] [length if necessary][data]...
$ hexdump /tmp/request.bin
0000000 0a 05 68 65 6c 6c 6f
0a is “0000 1010”, so
field_number = 1 and wire_type = 2
Protocol Buffer IDL
message EchoMessage {
string text = 1;
// other fields...
}
Protocol Buffer Methodology
% protoc echo.proto --go_out=.
# This runs the Protocol Buffer Compiler
# (https://github.com/protocolbuffers/protobuf/releases)
#
# with a plugin called protoc-gen-go
#
# The plugin generates a Go source file that implements
# the data structures defined in echo.proto and code
# for reading and writing them as serialized bytes.
gRPC scales to many programming languages.
Java
Service
Python
Service
Go
Service
C++
Service
gRPC
Server
gRPC
Stub
gRPC
Stub
gRPC
Stub
gRPC
Stub
gRPC
Server
gRPC
Server
gRPC
Server
gRPC
Stub
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC by Tim Burks
gRPC scales to distributed systems.
gRPC is open and extensible.
gRPC has a style guide.
gRPC supports Generated API Clients.
GAPICs: Trivial Getting-Started Experience
GAPIC client:
Channel channel =
NettyChannelBuilder.forAddress(API_ENTRY, API_PORT).build();
List<ClientInterceptor> interceptors = new ArrayList<>();
GoogleCredentials credentials =
GoogleCredentials.getApplicationDefault();
interceptors.add(
ChannelFactory.credentialInterceptor(credentials));
LoggingService stub =
LoggingServiceGrpc.newBlockingStub(channel, interceptors);
gRPC:
LoggingClient client = LoggingClient.create();
GAPICs: Flattening, Automatic Retry
GAPIC client:
LoggingService stub = ...;
// Note: this only does a simple retry, exponential backoff
// is more complex
DeleteLogRequest request = DeleteLogRequest.newBuilder()
.setLogName(LOG_NAME)
.build();
for (int i = 0; i < MAX_RETRY; i++) {
try {
stub.deleteLog(request);
} catch (RpcException e) {
if (i == MAX_RETRY) throw e;
}
}
gRPC:
LoggingClient client = LoggingClient.create();
client.deleteLog(LOG_NAME);
GAPICs: Natural Pagination
GAPIC client:
LoggingService stub = ...;
ListLogsRequest request = ListLogsRequest.newBuilder()
.setParentName("projects/" + PROJECT_ID)
.build();
while (true) {
ListLogsResponse response = stub.listLogs(request);
for (Log log : response.getLogsList()) {
System.out.printf("Log: %s%n", log.getDisplayName());
}
String nextPageToken = response.getNextPageToken();
if (nextPageToken != null) {
request = ListLogsRequest.newBuilder()
.setPageToken(nextPageToken).build();
} else {
break;
}
}
gRPC:
LoggingClient client = LoggingClient.create();
ParentNameOneOf parent =
ParentNameOneOf.from(ProjectName.create(PROJECT_ID));
for (Log log : client.listLogs(PARENT).iterateAll()) {
System.out.printf("Log: %s%n", log.getDisplayName());
}
GAPICs: Long-Running Operations
SpeechClient speechClient = SpeechClient.create();
OperationFuture<LongRunningRecognizeResponse> recognizeOperation =
speechClient.longRunningRecognizeAsync(config, audio);
…
LongRunningRecognizeResponse response = recognizeOperation.get();
● Java: OperationFuture
○ Polls the service until the LRO is done
○ Provides metadata as the LRO is in progress
○ Provides the final result
GAPICs: Resource Name Types
GAPIC client:
PublisherService stub = ...;
CreateTopicRequest request = CreateTopicRequest.newBuilder()
.setTopic("projects/my-project/topics/my-topic")
.build();
Topic response = stub.createTopic(request);
gRPC:
TopicAdminClient topicAdminClient = TopicAdminClient.create();
TopicName name = TopicName.create("my-project", "my-topic");
Topic response = topicAdminClient.createTopic(name);
GAPIC Project Architecture (at github.com/googleapis)
gapic-generator-python
Wanted: Swift, Rust, Dart...
gapic-generator
(java, php, python, go,
csharp, node, ruby)
gapic-generator-ruby
gapic-generator-go
gapic-generator-typescript
gapic-generator-csharp
One API
description
(Annotated
.proto files)
Many
language-
specific
client
libraries
“Showcase” API verification
protoc-gen-go_cli
A protoc plugin that generates
CLIs in Go for APIs described
with protocol buffers.
gRPC supports Generated Command-Line Interfaces.
gRPC-Web Supports Browser Apps.
● Call gRPC from Browsers (Javascript, Dart)
● Proxy with Envoy
● Third party implementations
(github.com/improbable-eng/grpc-web)
gRPC Supports Reflection.
● Protocol Discussion
● Go implementation (example)
● Specification (protos)
gRPC works with API Management.
3
Implementing
OpenAPI Services
with gRPC
Build a gRPC service, get a free REST API!
Originally defined in google/api/http.proto
Now documented in AIP-127: HTTP and gRPC Transcoding
service Display {
rpc CreateKiosk(Kiosk) returns (Kiosk) {
option (google.api.http) = {post:"/v1/kiosks"};
}
rpc GetKiosk(GetKioskRequest) returns (Kiosk) {
option (google.api.http) =
{get: "/v1/kiosks/{id}" };
}
rpc DeleteKiosk(DeleteKioskRequest)
returns (google.protobuf.Empty) {
option (google.api.http) =
{ delete: "/v1/signs/{id}" };
}
[...]
}
Add REST annotations to your service
gRPC definitions with HTTP annotations
service Display {
rpc CreateKiosk(Kiosk) returns (Kiosk) {
}
rpc GetKiosk(GetKioskRequest) returns(Kiosk) {
}
rpc DeleteKiosk(DeleteKioskRequest)
returns (google.protobuf.Empty) {
}
[...]
}
gRPC definitions
# Call the CreateKiosk method
$ curl -d '{"name":"HTTP Kiosk", "size": { width: 1080, height: 720 } }' 
localhost:8082/v1/kiosks?key=AIzaSy[...]bBo
# Call the GetKiosk method
$ curl localhost:8082/v1/kiosks/1?key=AIzaSy[...]bBo
Now you can use HTTP+JSON!
gnostic-grpc
● 6 useful things I learned from GSoC
● How to build a REST API with gRPC and get
the best of two worlds
● gnostic-grpc (end-to-end example)
● Envoy gRPC-JSON transcoding
4
Implementing
GraphQL Services
with gRPC
Code-first or Schema-first?
● Evolving the Graph (Jon Wong, Coursera)
● Hard-Learned GraphQL Lessons: Based on
a True Story (Natalie Qabazard & Aditi
Garg, Trulia)
● The Problems of "Schema-First" GraphQL
Server Development (Nikolas Burk, Prisma)
Code-first GraphQL with Rejoiner
Medallion (Rejoiner demo by Danny Baggett)
Sample query (Rejoiner + Medallion)
{
events {
id
name
olympics {
year
season
}
olympians {
id
gender
last
first
}
}
}
Sample query (Rejoiner + Medallion)
{
getEvents(input: {year: 2018, season: "WINTER"}) {
id
name
}
}
Let’s hand-wrap a gRPC service (graphql-showcase)
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC by Tim Burks
Impressions / Project Ideas
gRPC has a lot of API information in the .proto files and we
can extend that with annotations.
There are some gaps between GraphQL assumptions and
gRPC practices that we would want to smooth with
configuration or conventions.
We could generate a GraphQL interface directly from gRPC
reflection.
Can we define a standard for gRPC-GraphQL transcoding?
apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC by Tim Burks

More Related Content

What's hot (20)

PDF
apidays LIVE Hong Kong 2021 - Multi-Protocol APIs at Scale in Adidas by Jesus...
apidays
 
PDF
Scaling Your Team With GraphQL: Why Relationships Matter
Joel Bowen
 
PDF
Itb 2021 - Bulding Quick APIs by Gavin Pickin
Gavin Pickin
 
PPTX
Into to GraphQL
shobot
 
PPTX
INTERFACE by apidays_What's your Type? Understanding API Types and Choosing t...
apidays
 
PDF
OpenAPI Spec at Google (Open API Initiative Meetup on 2016-09-15)
Open API Initiative (OAI)
 
PDF
apidays LIVE New York 2021 - Introduction to HATEOAS with Ketting by Evert Po...
apidays
 
PDF
Build pipelines with TeamCity and Kotlin DSL
Anton Arhipov
 
PDF
System design and architecture GgraphQL Public
Bogdan Nedelcu
 
PPTX
GraphQL-ify your APIs - Devoxx UK 2021
Soham Dasgupta
 
PDF
Designing APIs with OpenAPI Spec
Adam Paxton
 
PPTX
Running the-next-generation-of-cloud-native-applications-using-open-applicati...
NaveedAhmad239
 
PDF
GraphQL Munich Meetup #1 - How We Use GraphQL At Commercetools
Nicola Molinari
 
PPTX
API-first development
Vasco Veloso
 
PDF
GraphQL Europe Recap
Philipp Sporrer
 
PDF
Real Time Serverless Polling App
Srushith Repakula
 
PDF
Transformacion e innovacion digital Meetup - Application Modernization and Mi...
José Román Martín Gil
 
PDF
MuleSoft Surat Live Demonstration Virtual Meetup#5 - Salesforce Composite Con...
Jitendra Bafna
 
PDF
Continuous Delivery in a content centric world
Jeroen Reijn
 
PDF
apidays LIVE Paris 2021 - Stargate.io, An OSS Api Layer for your Cassandra by...
apidays
 
apidays LIVE Hong Kong 2021 - Multi-Protocol APIs at Scale in Adidas by Jesus...
apidays
 
Scaling Your Team With GraphQL: Why Relationships Matter
Joel Bowen
 
Itb 2021 - Bulding Quick APIs by Gavin Pickin
Gavin Pickin
 
Into to GraphQL
shobot
 
INTERFACE by apidays_What's your Type? Understanding API Types and Choosing t...
apidays
 
OpenAPI Spec at Google (Open API Initiative Meetup on 2016-09-15)
Open API Initiative (OAI)
 
apidays LIVE New York 2021 - Introduction to HATEOAS with Ketting by Evert Po...
apidays
 
Build pipelines with TeamCity and Kotlin DSL
Anton Arhipov
 
System design and architecture GgraphQL Public
Bogdan Nedelcu
 
GraphQL-ify your APIs - Devoxx UK 2021
Soham Dasgupta
 
Designing APIs with OpenAPI Spec
Adam Paxton
 
Running the-next-generation-of-cloud-native-applications-using-open-applicati...
NaveedAhmad239
 
GraphQL Munich Meetup #1 - How We Use GraphQL At Commercetools
Nicola Molinari
 
API-first development
Vasco Veloso
 
GraphQL Europe Recap
Philipp Sporrer
 
Real Time Serverless Polling App
Srushith Repakula
 
Transformacion e innovacion digital Meetup - Application Modernization and Mi...
José Román Martín Gil
 
MuleSoft Surat Live Demonstration Virtual Meetup#5 - Salesforce Composite Con...
Jitendra Bafna
 
Continuous Delivery in a content centric world
Jeroen Reijn
 
apidays LIVE Paris 2021 - Stargate.io, An OSS Api Layer for your Cassandra by...
apidays
 

Similar to apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC by Tim Burks (20)

PDF
Implementing OpenAPI and GraphQL services with gRPC
Tim Burks
 
PPTX
CocoaConf: The Language of Mobile Software is APIs
Tim Burks
 
PDF
gRPC or Rest, why not both?
Mohammad Murad
 
PDF
Fast and Reliable Swift APIs with gRPC
Tim Burks
 
PDF
gRPC - RPC rebirth?
Luís Barbosa
 
PDF
Building REST APIs using gRPC and Go
Alvaro Viebrantz
 
PDF
Creating Great REST and gRPC API Experiences (in Swift)
Tim Burks
 
PDF
Building Language Agnostic APIs with gRPC - JavaDay Istanbul 2017
Mustafa AKIN
 
PDF
Build Great Networked APIs with Swift, OpenAPI, and gRPC
Tim Burks
 
PDF
gRPC: Beyond REST
Domingo Suarez Torres
 
PPTX
The new (is it really ) api stack
Red Hat
 
PPTX
What I learned about APIs in my first year at Google
Tim Burks
 
PDF
gRPC with java
Knoldus Inc.
 
PPTX
Modern webservices using gRPC and Protocol Buffers in Golang
OmidHojabri1
 
PDF
Power-up services with gRPC
The Software House
 
PDF
マイクロサービスバックエンドAPIのためのRESTとgRPC
disc99_
 
PPTX
Demystifying gRPC in .Net by John Staveley
John Staveley
 
PDF
gRPC Design and Implementation
Varun Talwar
 
PPTX
Building API Using GRPC And Scala
Knoldus Inc.
 
Implementing OpenAPI and GraphQL services with gRPC
Tim Burks
 
CocoaConf: The Language of Mobile Software is APIs
Tim Burks
 
gRPC or Rest, why not both?
Mohammad Murad
 
Fast and Reliable Swift APIs with gRPC
Tim Burks
 
gRPC - RPC rebirth?
Luís Barbosa
 
Building REST APIs using gRPC and Go
Alvaro Viebrantz
 
Creating Great REST and gRPC API Experiences (in Swift)
Tim Burks
 
Building Language Agnostic APIs with gRPC - JavaDay Istanbul 2017
Mustafa AKIN
 
Build Great Networked APIs with Swift, OpenAPI, and gRPC
Tim Burks
 
gRPC: Beyond REST
Domingo Suarez Torres
 
The new (is it really ) api stack
Red Hat
 
What I learned about APIs in my first year at Google
Tim Burks
 
gRPC with java
Knoldus Inc.
 
Modern webservices using gRPC and Protocol Buffers in Golang
OmidHojabri1
 
Power-up services with gRPC
The Software House
 
マイクロサービスバックエンドAPIのためのRESTとgRPC
disc99_
 
Demystifying gRPC in .Net by John Staveley
John Staveley
 
gRPC Design and Implementation
Varun Talwar
 
Building API Using GRPC And Scala
Knoldus Inc.
 
Ad

More from apidays (20)

PPTX
apidays Helsinki & North 2025 - From Chaos to Clarity: Designing (AI-Ready) A...
apidays
 
PPTX
apidays Helsinki & North 2025 - Running a Successful API Program: Best Practi...
apidays
 
PPTX
apidays Helsinki & North 2025 - Agentic AI: A Friend or Foe?, Merja Kajava (A...
apidays
 
PPTX
apidays Helsinki & North 2025 - APIs at Scale: Designing for Alignment, Trust...
apidays
 
PPTX
apidays Helsinki & North 2025 - API access control strategies beyond JWT bear...
apidays
 
PPTX
apidays Singapore 2025 - Designing for Change, Julie Schiller (Google)
apidays
 
PPTX
apidays Singapore 2025 - From Data to Insights: Building AI-Powered Data APIs...
apidays
 
PPTX
apidays Singapore 2025 - The Quest for the Greenest LLM , Jean Philippe Ehre...
apidays
 
PDF
apidays Singapore 2025 - The API Playbook for AI by Shin Wee Chuang (PAND AI)
apidays
 
PDF
apidays Singapore 2025 - Trustworthy Generative AI: The Role of Observability...
apidays
 
PDF
apidays Singapore 2025 - Streaming Lakehouse with Kafka, Flink and Iceberg by...
apidays
 
PDF
apidays Singapore 2025 - How APIs can make - or break - trust in your AI by S...
apidays
 
PDF
apidays Singapore 2025 - From API Intelligence to API Governance by Harsha Ch...
apidays
 
PPTX
apidays Singapore 2025 - Generative AI Landscape Building a Modern Data Strat...
apidays
 
PDF
apidays Singapore 2025 - Building a Federated Future, Alex Szomora (GSMA)
apidays
 
PDF
apidays Singapore 2025 - Surviving an interconnected world with API governanc...
apidays
 
PDF
apidays Singapore 2025 - What exactly are AI Agents by Aki Ranin (Earthshots ...
apidays
 
PPTX
apidays Singapore 2025 - Enhancing Developer Productivity with UX (Government...
apidays
 
PDF
apidays Singapore 2025 - Building Finance Innovation Ecosystems by Umang Moon...
apidays
 
PPTX
apidays Singapore 2025 - 4 Identity Essentials for Scaling SaaS in Large Orgs...
apidays
 
apidays Helsinki & North 2025 - From Chaos to Clarity: Designing (AI-Ready) A...
apidays
 
apidays Helsinki & North 2025 - Running a Successful API Program: Best Practi...
apidays
 
apidays Helsinki & North 2025 - Agentic AI: A Friend or Foe?, Merja Kajava (A...
apidays
 
apidays Helsinki & North 2025 - APIs at Scale: Designing for Alignment, Trust...
apidays
 
apidays Helsinki & North 2025 - API access control strategies beyond JWT bear...
apidays
 
apidays Singapore 2025 - Designing for Change, Julie Schiller (Google)
apidays
 
apidays Singapore 2025 - From Data to Insights: Building AI-Powered Data APIs...
apidays
 
apidays Singapore 2025 - The Quest for the Greenest LLM , Jean Philippe Ehre...
apidays
 
apidays Singapore 2025 - The API Playbook for AI by Shin Wee Chuang (PAND AI)
apidays
 
apidays Singapore 2025 - Trustworthy Generative AI: The Role of Observability...
apidays
 
apidays Singapore 2025 - Streaming Lakehouse with Kafka, Flink and Iceberg by...
apidays
 
apidays Singapore 2025 - How APIs can make - or break - trust in your AI by S...
apidays
 
apidays Singapore 2025 - From API Intelligence to API Governance by Harsha Ch...
apidays
 
apidays Singapore 2025 - Generative AI Landscape Building a Modern Data Strat...
apidays
 
apidays Singapore 2025 - Building a Federated Future, Alex Szomora (GSMA)
apidays
 
apidays Singapore 2025 - Surviving an interconnected world with API governanc...
apidays
 
apidays Singapore 2025 - What exactly are AI Agents by Aki Ranin (Earthshots ...
apidays
 
apidays Singapore 2025 - Enhancing Developer Productivity with UX (Government...
apidays
 
apidays Singapore 2025 - Building Finance Innovation Ecosystems by Umang Moon...
apidays
 
apidays Singapore 2025 - 4 Identity Essentials for Scaling SaaS in Large Orgs...
apidays
 
Ad

Recently uploaded (20)

PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 

apidays LIVE Helsinki - Implementing OpenAPI and GraphQL Services with gRPC by Tim Burks

  • 1. Implementing OpenAPI and GraphQL Services with gRPC Tim Burks ([email protected], @timburks)
  • 2. 1. API technologies: OpenAPI, GraphQL, gRPC 2. Why implement your API with gRPC? 3. Implementing OpenAPI services with gRPC 4. Implementing GraphQL services with gRPC Topics
  • 4. Five Questions about API Systems 1. What problem is this API system addressing? 2. How are APIs called? 3. How are APIs built? 4. What’s great about this? 5. What’s challenging about this?
  • 5. What problem is OpenAPI addressing? “The OpenAPI Specification, originally known as the Swagger Specification, is a specification for machine-readable interface files for describing, producing, consuming, and visualizing RESTful web services.” Wikipedia
  • 6. How an OpenAPI service is called: You might call it from your browser. In your applications, you call it from code. openapi-generator autorest APIMatic SwagGen (Swift) Paperclip (Rust)
  • 7. How an OpenAPI service is built: 🤞 Code-first Handwritten implementations. Handwritten API descriptions. ⚙ Code-first (better) Handwritten implementations. API descriptions generated from code. 📐 Spec-first Handwritten API descriptions. Implementations generated from API descriptions.
  • 8. What’s great about OpenAPI: ● Standards and tools make it easy to get started. ○ HTTP ○ JSON/YAML ● Very popular - large community.
  • 9. What’s challenging about OpenAPI: “Unfortunately, many of the APIs that claim to be RESTful layer a lot of proprietary concepts on top of HTTP. Essentially, they invent their own API and use HTTP as a lower-level transport layer, rather than using HTTP directly as it was designed. In fact, there’s so much variability in the way that people use the term REST in the context of APIs that it’s difficult to know what they mean by it unless you know them well.” Martin Nally
  • 10. What problem is GraphQL addressing? “GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.” graphql.org
  • 11. How a GraphQL service is called: “With express-graphql, you can just send an HTTP POST request to the endpoint you mounted your GraphQL server on, passing the GraphQL query as the query field in a JSON payload.” https://graphql.org/graphql-js/graphql-clients/ Also GraphiQL!
  • 12. How a GraphQL service is built: ● Code-first, schema extracted from code ● Schema-first - code generated from SDL ● Generated from underlying APIs ○ Federated from other GraphQL APIs ○ OpenAPI-to-GraphQL ○ rejoiner
  • 13. What’s great about GraphQL: ● Simple client-side interface ● Optimizes for client performance ● Layered on familiar technology ● Sharable BFF
  • 14. What’s challenging about GraphQL: ● Complex implementation ● Performance challenges ● Versioning ● Schema design Public GraphQL APIs are rare.
  • 15. What problem is gRPC addressing? “gRPC is a modern open source high performance RPC framework that can run in any environment. It can efficiently connect services in and across data centers with pluggable support for load balancing, tracing, health checking and authentication. It is also applicable in last mile of distributed computing to connect devices, mobile applications and browsers to backend services.” grpc.io
  • 16. How a gRPC service is called: ALWAYS specification-first. Clients are generated from API descriptions written in the Protocol Buffer language.
  • 17. How a gRPC service is built: ALWAYS specification-first. Service code is generated. Typically this generated code declares an interface that is implemented in language-native data structures and patterns.
  • 18. What’s great about gRPC: So much is built-in. High performance. Cross-language compatibility. Potential for very nice client integration.
  • 19. What’s challenging about gRPC: Some learning and tooling is required!
  • 21. gRPC APIs have a native language. Protocol Buffers
  • 22. Protocol Buffers is a language-neutral, platform-neutral, extensible mechanism for serializing structured data.
  • 23. “Protocol Buffers” means several things 1. A serialization mechanism 2. An interface description language 3. A methodology
  • 24. Protocol Buffer Serialization A message is just a stream of bytes [field_number<<3 + wire_type] [length if necessary][data]... $ hexdump /tmp/request.bin 0000000 0a 05 68 65 6c 6c 6f 0a is “0000 1010”, so field_number = 1 and wire_type = 2
  • 25. Protocol Buffer IDL message EchoMessage { string text = 1; // other fields... }
  • 26. Protocol Buffer Methodology % protoc echo.proto --go_out=. # This runs the Protocol Buffer Compiler # (https://github.com/protocolbuffers/protobuf/releases) # # with a plugin called protoc-gen-go # # The plugin generates a Go source file that implements # the data structures defined in echo.proto and code # for reading and writing them as serialized bytes.
  • 27. gRPC scales to many programming languages. Java Service Python Service Go Service C++ Service gRPC Server gRPC Stub gRPC Stub gRPC Stub gRPC Stub gRPC Server gRPC Server gRPC Server gRPC Stub
  • 29. gRPC scales to distributed systems.
  • 30. gRPC is open and extensible.
  • 31. gRPC has a style guide.
  • 32. gRPC supports Generated API Clients.
  • 33. GAPICs: Trivial Getting-Started Experience GAPIC client: Channel channel = NettyChannelBuilder.forAddress(API_ENTRY, API_PORT).build(); List<ClientInterceptor> interceptors = new ArrayList<>(); GoogleCredentials credentials = GoogleCredentials.getApplicationDefault(); interceptors.add( ChannelFactory.credentialInterceptor(credentials)); LoggingService stub = LoggingServiceGrpc.newBlockingStub(channel, interceptors); gRPC: LoggingClient client = LoggingClient.create();
  • 34. GAPICs: Flattening, Automatic Retry GAPIC client: LoggingService stub = ...; // Note: this only does a simple retry, exponential backoff // is more complex DeleteLogRequest request = DeleteLogRequest.newBuilder() .setLogName(LOG_NAME) .build(); for (int i = 0; i < MAX_RETRY; i++) { try { stub.deleteLog(request); } catch (RpcException e) { if (i == MAX_RETRY) throw e; } } gRPC: LoggingClient client = LoggingClient.create(); client.deleteLog(LOG_NAME);
  • 35. GAPICs: Natural Pagination GAPIC client: LoggingService stub = ...; ListLogsRequest request = ListLogsRequest.newBuilder() .setParentName("projects/" + PROJECT_ID) .build(); while (true) { ListLogsResponse response = stub.listLogs(request); for (Log log : response.getLogsList()) { System.out.printf("Log: %s%n", log.getDisplayName()); } String nextPageToken = response.getNextPageToken(); if (nextPageToken != null) { request = ListLogsRequest.newBuilder() .setPageToken(nextPageToken).build(); } else { break; } } gRPC: LoggingClient client = LoggingClient.create(); ParentNameOneOf parent = ParentNameOneOf.from(ProjectName.create(PROJECT_ID)); for (Log log : client.listLogs(PARENT).iterateAll()) { System.out.printf("Log: %s%n", log.getDisplayName()); }
  • 36. GAPICs: Long-Running Operations SpeechClient speechClient = SpeechClient.create(); OperationFuture<LongRunningRecognizeResponse> recognizeOperation = speechClient.longRunningRecognizeAsync(config, audio); … LongRunningRecognizeResponse response = recognizeOperation.get(); ● Java: OperationFuture ○ Polls the service until the LRO is done ○ Provides metadata as the LRO is in progress ○ Provides the final result
  • 37. GAPICs: Resource Name Types GAPIC client: PublisherService stub = ...; CreateTopicRequest request = CreateTopicRequest.newBuilder() .setTopic("projects/my-project/topics/my-topic") .build(); Topic response = stub.createTopic(request); gRPC: TopicAdminClient topicAdminClient = TopicAdminClient.create(); TopicName name = TopicName.create("my-project", "my-topic"); Topic response = topicAdminClient.createTopic(name);
  • 38. GAPIC Project Architecture (at github.com/googleapis) gapic-generator-python Wanted: Swift, Rust, Dart... gapic-generator (java, php, python, go, csharp, node, ruby) gapic-generator-ruby gapic-generator-go gapic-generator-typescript gapic-generator-csharp One API description (Annotated .proto files) Many language- specific client libraries
  • 40. protoc-gen-go_cli A protoc plugin that generates CLIs in Go for APIs described with protocol buffers. gRPC supports Generated Command-Line Interfaces.
  • 41. gRPC-Web Supports Browser Apps. ● Call gRPC from Browsers (Javascript, Dart) ● Proxy with Envoy ● Third party implementations (github.com/improbable-eng/grpc-web) gRPC Supports Reflection. ● Protocol Discussion ● Go implementation (example) ● Specification (protos)
  • 42. gRPC works with API Management.
  • 44. Build a gRPC service, get a free REST API! Originally defined in google/api/http.proto Now documented in AIP-127: HTTP and gRPC Transcoding
  • 45. service Display { rpc CreateKiosk(Kiosk) returns (Kiosk) { option (google.api.http) = {post:"/v1/kiosks"}; } rpc GetKiosk(GetKioskRequest) returns (Kiosk) { option (google.api.http) = {get: "/v1/kiosks/{id}" }; } rpc DeleteKiosk(DeleteKioskRequest) returns (google.protobuf.Empty) { option (google.api.http) = { delete: "/v1/signs/{id}" }; } [...] } Add REST annotations to your service gRPC definitions with HTTP annotations service Display { rpc CreateKiosk(Kiosk) returns (Kiosk) { } rpc GetKiosk(GetKioskRequest) returns(Kiosk) { } rpc DeleteKiosk(DeleteKioskRequest) returns (google.protobuf.Empty) { } [...] } gRPC definitions
  • 46. # Call the CreateKiosk method $ curl -d '{"name":"HTTP Kiosk", "size": { width: 1080, height: 720 } }' localhost:8082/v1/kiosks?key=AIzaSy[...]bBo # Call the GetKiosk method $ curl localhost:8082/v1/kiosks/1?key=AIzaSy[...]bBo Now you can use HTTP+JSON!
  • 47. gnostic-grpc ● 6 useful things I learned from GSoC ● How to build a REST API with gRPC and get the best of two worlds ● gnostic-grpc (end-to-end example) ● Envoy gRPC-JSON transcoding
  • 49. Code-first or Schema-first? ● Evolving the Graph (Jon Wong, Coursera) ● Hard-Learned GraphQL Lessons: Based on a True Story (Natalie Qabazard & Aditi Garg, Trulia) ● The Problems of "Schema-First" GraphQL Server Development (Nikolas Burk, Prisma)
  • 51. Medallion (Rejoiner demo by Danny Baggett)
  • 52. Sample query (Rejoiner + Medallion) { events { id name olympics { year season } olympians { id gender last first } } }
  • 53. Sample query (Rejoiner + Medallion) { getEvents(input: {year: 2018, season: "WINTER"}) { id name } }
  • 54. Let’s hand-wrap a gRPC service (graphql-showcase)
  • 56. Impressions / Project Ideas gRPC has a lot of API information in the .proto files and we can extend that with annotations. There are some gaps between GraphQL assumptions and gRPC practices that we would want to smooth with configuration or conventions. We could generate a GraphQL interface directly from gRPC reflection. Can we define a standard for gRPC-GraphQL transcoding?