W-19424007 (SPIKE) Try Panel gRPC support with new proto definitions #873
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
example.proto
for gRPC service definition withSayHello
method.package.json
andpackage-lock.json
to includegrpc-web
andprotobufjs
dependencies.ApiConsole
to handle gRPC operations, including request schema extraction and dynamic message creation.ApiConsoleStyles.js
.Spike: gRPC Integration in API Console
Objective
Evaluate the technical feasibility of integrating gRPC support into API Console, enabling visualization of gRPC API metadata (using JSON-LD generated by AMF) and testing operations (e.g.,
Greeter.SayHello1
) via a "Try It" panel in the browser, while maintaining compatibility with REST/RAML.Context
API Console currently supports REST/RAML and YAML APIs used by MuleSoft products like Design Center and Exchange. This spike explores:
grpc.json
, with serviceGreeter
, methodsSayHello1
/SayHello2
, and messagesHelloRequest
/HelloReply
).Proposed Architecture
Main Components
Technology Stack
grpc-web
(for browser).protobufjs
(to interpret JSON-LD and build messages).@grpc-web/proxy
(Node.js) or Envoy (production).@grpc/grpc-js
(for local testing).npm install grpc-web protobufjs @grpc-web/proxy @grpc/grpc-js
.Implementation
1. Detecting gRPC Operations
Detect if an operation is gRPC by checking the
mediaType
in the JSON-LD:2. Parsing JSON-LD for Schemas
Extract services, methods, and messages from JSON-LD to generate the UI:
3. UI for the Try Panel
Add a panel with a form and a "Try gRPC Request" button:
4. gRPC-Web Client
Use
grpc-web
to send requests to the proxy:5. gRPC-Web Proxy Configuration
The proxy is critical to translate gRPC-Web to native gRPC, as browsers do not support full HTTP/2. We use
@grpc-web/proxy
for local testing:6. Local gRPC Server (for Testing)
Implemented a test server in Node.js to simulate
Greeter
:Challenges and Considerations
1. Proxy Configuration
@grpc-web/proxy
or Envoy) translates gRPC-Web to native gRPC.@grpc-web/proxy
is an npm module, easy to share via an internal registry (e.g.,@mulesoft/grpc-web-proxy
).envoy.yaml
, run with Docker).setupGrpcWebProxy --port 8080 --upstream :50051
).2. JSON-LD Parsing
grpc.json
) contains services (Greeter
), methods (SayHello1
), and messages (HelloRequest
withname
,wadus
). Parsingshacl#property
andshapes#range
recursively for nested messages and enums.protobufjs
to convert JSON-LD to a dynamic protobuf schema, generating forms in the try panel.3. RPC Types
SayHello1
).grpc-web
callbacks.4. Security
cors
middleware).grpc-web
.5. MuleSoft Compatibility
Next Steps
Phase 1: Fundamentals
@grpc-web/proxy
) for teams.Phase 2: Streaming and Features
Phase 3: UX and Adoption
@mulesoft/grpc-web-proxy
as an internal npm module.Conclusions
Feasibility
gRPC integration in API Console is feasible using:
protobufjs
).grpc-web
for browser requests.@grpc-web/proxy
or Envoy to connect to gRPC servers.Recommendations
grpcui
for initial local testing.Risks
References