Implementation Procedure
Prerequisites
- Both the client and server are of the gRPC type.
- The server 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 server.
Creating an API
- Log in to the APIG console.
- Select a gateway at the top of the navigation pane.
- In the navigation pane, choose API Management > APIs.
- Click Create API > Create gRPC API. For details, see Creating a gRPC API.
- Configure frontend information and click Next.
Table 1 Frontend configuration Parameter
Description
API Name
Enter a name that conforms to specific rules to facilitate search.
Group
The default option is DEFAULT.
URL
Method: Request method of the API. Default: POST.
Protocol: Request protocol of the API. Default: GRPCS.
Subdomain Name: The system automatically allocates a subdomain name to each API group for internal testing. The subdomain name can be accessed 1000 times a day.
Path: Path for requesting the API. In this example, enter /helloworld.Greeter. For details about the request path, see the proto file. helloworld indicates the package name, and Greeter indicates the service name.
Gateway Response
Select a response to be displayed if the gateway fails to process an API request.
The default gateway response is default.
Matching
Select Prefix match.
Authentication Mode
API authentication mode. Select None. (None: Not recommended for actual services. All users will be granted access to the API.)
- Configure the backend information and click Next.
Table 2 Backend configuration Parameter
Description
Load Balance Channel
Determine whether the backend service will be accessed using a load balance channel. For this example, select Skip.
URL
Method: Request method of the API. Default: POST.
Protocol: Request protocol of the backend service. Default: GRPCS.
Backend Address: Address and port of the backend service.
Path: Path of the backend service. In this example, enter /.
- Click Finish.
On the APIs page, the API URL only shows the domain name and path. It does not show the request method or protocol. When sending a gRPC request, enter the domain name.
Publishing the API
- On the APIs tab, select the created API and click Publish Latest Version.
- Select the environment where the API will be published, and enter a description.
- Click OK. After the API is published, the red exclamation mark (!) in the upper left corner of the Publish button disappears.
Verifying the API
Use the API test tool to invoke the created API, or invoke this API on a client.
- Enter the debugging domain name of the API's group.
- Import the proto file of the server.
The proto file contains the following content:
syntax = "proto3"; package helloworld; // The greeting service definition. service Greeter { // Sends a greeting rpc SayHello (HelloRequest) returns (HelloReply) {} } // The request message containing the user's name. message HelloRequest { string name = 1; } // The response message containing the greetings message HelloReply { string message = 1; }
- helloworld: package name
- Greeter: service name
- SayHello: method name
- HelloRequest: request body
- HelloReply: response body
- Enter an API request in the message area according to the proto file.
{ "name": "world" }
- Click Invoke to send the request.
- View the response in the Response area. If status code 0 OK is displayed, the invocation is successful.
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