Example
This section describes how to call the API for querying the service list. In the following example, instances are deployed on SpringCloudDemo. Spring Cloud is a microservice architecture development tool based on Spring Boot. It facilitates configuration management, service governance, circuit breakers, intelligent routing, micro-proxy, control bus, global locks, leadership election, distributed sessions, and cluster state management involved in the microservice architecture.
To call the API used to query the service list, do as follows:
- Obtain the token, which will be put into the request header for authentication in a subsequent request.
- Construct and initiate a request to call the API used to query the service list.
- View the obtained response, and check whether the API used to query the service list is successfully called.
Preparations:
- The SpringCloudDemo application has been deployed on the server.
- The endpoints of IAM and APM have been obtained. In this example, the endpoint of IAM is iam_Endpoint, and the endpoint of APM is apm_Endpoint.
- Obtain the token for authentication.
- Enter POST https://IAM endpoint/v3/auth/tokens. In this example, IAM endpoint is iam_Endpoint. Therefore, enter POST https://iam_Endpoint/v3/auth/tokens.
- After a response is returned, the value of X-Subject-Token in the response header is the token value.
Example request:
{ "auth": { "identity": { "methods": [ "password" ], "password": { "user": { "name": "username",//Replace the username as required. "password": "password",//Replace the password as required. "domain": { "name": "domainname"//Replace the domainname as required. } } } }, "scope": { "project": { "name": "ap-southeast-1" //ap-southeast-1 indicates the IAM region. Replace it as required. } } } }
- Construct a request and send it.
A request consists of three parts: a request line, request header, and request body (optional). Construct a request, send it, and wait for the response.
- Request line
GET https://Endpoint/v1/{project_id}/ats/applications
Endpoint indicates the endpoint of APM, which is apm_Endpoint in this example.
{project_id} indicates the path parameter.
Parameter
Type
Description
project_id
String
Project ID.
During token authentication, the response body contains the value of {project_id}, which is id: 12ff18574dfe4b92...... in this example.
Request line:
https://apm_Endpoint/v1/12ff18574dfe4b92....../ats/applications?monitorGroup=SpringCloudDemo
- Request header
X-Auth-Token. The value is the value of X-subject-token obtained in token authentication.
X-Auth-Token: MIIRpQYJKoZIhvcNAQcCoIIRljCCEZICAQExDTALBglghkgBZQMEAgEwgg-zBgkqhkiG9w0BBwGggg...
Content-Type: application/json;charset=utf8
- Request body (not involved in this example)
- Request line
- Receive the response.
After the request is sent, a response is returned.
Response:
{ "errorCode": "SVCSTG.ATS.2000", "errorMessage": null, "responseInfo": [ "spring-cloud-service-eureka-server", "spring-cloud-testservice-consumer", "spring-cloud-testservice-provider", "springboot1.2", "springboot1.3.8", "springboot1.4.7", "springboot1.5.13" ] }
The response consists of errorCode, errorMessage, and responseInfo.
responseInfo indicates all the services that are queried on SpringCloudDemo.
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