W-19424007 (SPIKE) Try Panel gRPC support with new proto definitions#873
Draft
W-19424007 (SPIKE) Try Panel gRPC support with new proto definitions#873
Conversation
…ancements - Introduced `example.proto` for gRPC service definition with `SayHello` method. - Updated `package.json` and `package-lock.json` to include `grpc-web` and `protobufjs` dependencies. - Enhanced `ApiConsole` to handle gRPC operations, including request schema extraction and dynamic message creation. - Added styles for gRPC request panel in `ApiConsoleStyles.js`. - Implemented form rendering for gRPC fields and handling of gRPC requests in the API console.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.protofor gRPC service definition withSayHellomethod.package.jsonandpackage-lock.jsonto includegrpc-webandprotobufjsdependencies.ApiConsoleto 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
graph TD A[API Console UI] -->|Parses| B[AMF JSON-LD Parser] A -->|Generates| C[gRPC Try Panel] C -->|Sends request| D[gRPC-Web Client] D -->|Translates HTTP/1.1 to HTTP/2| E[gRPC-Web Proxy] E -->|Native gRPC| F[gRPC Server] B -->|Extracts| G[JSON-LD Model: grpc.json] G -->|Converts to| H[Proto Schema] H -->|Used by| DTechnology 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
mediaTypein 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-webto 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/proxyfor 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/proxyor Envoy) translates gRPC-Web to native gRPC.@grpc-web/proxyis 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 (HelloRequestwithname,wadus). Parsingshacl#propertyandshapes#rangerecursively for nested messages and enums.protobufjsto convert JSON-LD to a dynamic protobuf schema, generating forms in the try panel.3. RPC Types
SayHello1).grpc-webcallbacks.4. Security
corsmiddleware).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-proxyas an internal npm module.Conclusions
Feasibility
gRPC integration in API Console is feasible using:
protobufjs).grpc-webfor browser requests.@grpc-web/proxyor Envoy to connect to gRPC servers.Recommendations
grpcuifor initial local testing.Risks
References