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 the frontend information according to the following table. Click Next.
Table 1 Frontend configuration Parameter
Description
API Name
Enter an API name.
Group
Group to which the API belongs. The default value 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 1,000 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 according to the following table. Click Finish.
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 /.
Publishing the API
- On the APIs tab, select the created API and click Publish Latest Version.
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.
- 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