Creating a gRPC API
APIG supports gRPC API creation. gRPC is a modern, open-source, high-performance Remote Procedure Call (RPC) framework that can run in any environment. You only need to define the request and response of each API, and let the gRPC framework take care of the rest. gRPC uses protocol buffers (protobuf) as its Interface Definition Language (IDL) and for bottom-layer message exchange. The following table compares gRPC and REST APIs.
Parameter |
gRPC |
REST |
---|---|---|
Message encoding |
protobuf |
JSON |
Transmission protocol |
HTTP/2 |
HTTP |
Transmission performance |
Fast, with less content to transmit |
More content to transmit |
Transmission mode |
Send a single request and receive a single response. |
If both your client and server are of the gRPC type, you can create an gRPC API to open up your backend capabilities. gRPC features low resource consumption and high transmission rate. It is suitable for internal service invocation and governance.
Restrictions
- gRPC APIs cannot be imported, exported, or debugged, and do not support the import of API design files, CSE microservices, or CCE workloads.
- Circuit breaker policies whose backend policy type is Mock, HTTP&HTTPS, or FunctionGraph are not supported.
Prerequisites
- You have created an API group. If no API group is available, create one by referring to Creating an API Group.
- If the backend service needs to use a load balance channel, create a channel first.
- The backend service has a proto file that defines API request and response parameters. The proto file is used in gRPC to define data structures and service APIs. It describes data structures and interactions using protobuf and serves as a contract for communication between the client and backend services.
Procedure
- Go to the APIG console.
- Select a gateway at the top of the navigation pane.
- In the navigation pane, choose API Management > API Groups.
- Click a group name.
- On the APIs tab page, choose Create API > Create gRPC API.
- Configure the frontend definition according to 5.a.
For gRPC APIs, the default frontend request method is POST and the protocol is GRPCS.
Set the path to any of the following:- /
- /{Package name}.{Service name}
- /{Package name}.{Service name}/{Method name}
- Obtain the package name, service name, and method name from the proto file.
- Absolute match can be used only when the frontend path is set to /{Package name}.{Service name}/{Method name}.
- Base64 encoding is not supported.
- Configure the authentication mode by referring to 5.b.
- Click Next.
- Configure the default backend by referring to 1.
The backend service type of gRPC APIs can be GRPC&GRPCS or FunctionGraph.
- When the type is GRPC&GRPCS, the backend service uses the POST request method, / path, and GRPC or GRPCS protocol, and does not support parameter orchestration.
- When the type is FunctionGraph, the backend service uses V2 network architecture and Synchronous invocation type by default, and does not support parameter orchestration.
gRPC APIs with a FunctionGraph backend are supported in CN Southwest-Guiyang1, CN East-Shanghai1, CN North-Beijing4, CN East-Shanghai2, and LA-Santiago.
- (Optional) Add a backend policy by referring to 5.
(Optional) Creating a Policy
You can create policies for the API after publishing it.
- On the APIs tab, click Create Policy.
- Select a policy type and set parameters.
- Select existing policy
- Create new policy (see Configuring API Policies)
- Click OK.
Related Documents
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot