This is an automated email from the ASF dual-hosted git repository.
gongchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git
The following commit(s) were added to refs/heads/master by this push:
new a83cb0f50f [docs] Fix HTTP Service Discovery API response format
(#4005)
a83cb0f50f is described below
commit a83cb0f50f95a4609cb88db369ab8c96942a3073
Author: LunaRain_079 <[email protected]>
AuthorDate: Thu Jan 29 22:10:15 2026 +0800
[docs] Fix HTTP Service Discovery API response format (#4005)
---
home/docs/help/http_sd.md | 76 ++++++++++++----------
.../current/help/http_sd.md | 76 ++++++++++++----------
.../version-1.7.x/help/http_sd.md | 76 ++++++++++++----------
home/versioned_docs/version-1.7.x/help/http_sd.md | 76 ++++++++++++----------
4 files changed, 164 insertions(+), 140 deletions(-)
diff --git a/home/docs/help/http_sd.md b/home/docs/help/http_sd.md
index fd29acd77d..5cd0c58f8e 100644
--- a/home/docs/help/http_sd.md
+++ b/home/docs/help/http_sd.md
@@ -18,21 +18,23 @@ HTTP Service Discovery allows HertzBeat to discover service
instances by calling
You need to provide or develop an HTTP API that meets the following
requirements:
1. **HTTP Method**: Support GET requests
-2. **Response Format**: Return JSON format data
-3. **Response Structure**: Must contain a `targets` field, which is a string
array. Each string is a service instance address in the format `host:port`
+2. **Response Format**: Return JSON array format
+3. **Response Structure**: Must be an array format, each element contains a
`target` field (note: singular), which is a string array. Each string is a
service instance address in the format `host:port`
4. **Accessibility**: The API must be accessible from HertzBeat
#### API Response Example
```json
-{
- "targets": [
- "192.168.1.101:8080",
- "192.168.1.102:8080",
- "192.168.1.103:8080",
- "api.example.com:443"
- ]
-}
+[
+ {
+ "target": [
+ "192.168.1.101:8080",
+ "192.168.1.102:8080",
+ "192.168.1.103:8080",
+ "api.example.com:443"
+ ]
+ }
+]
```
### Configuration parameter
@@ -81,13 +83,15 @@ Suppose you have a service management API:
- **Response**:
```json
- {
- "targets": [
- "10.0.1.10:8080",
- "10.0.1.11:8080",
- "10.0.1.12:8080"
- ]
- }
+ [
+ {
+ "target": [
+ "10.0.1.10:8080",
+ "10.0.1.11:8080",
+ "10.0.1.12:8080"
+ ]
+ }
+ ]
```
Configuration example:
@@ -134,7 +138,7 @@ Configuration example:
### Notes
-- **Response Format**: The API response must be in JSON format and contain a
`targets` field (string array)
+- **Response Format**: The API response must be in JSON array format, each
element contains a `target` field (note: singular, string array)
- **Address Format**: Each target address should be in the format `host:port`,
for example:
- `192.168.1.100:8080`
- `api.example.com:443`
@@ -171,21 +175,23 @@ Configuration example:
#### Response with Additional Metadata
-While the basic requirement is just the `targets` field, your API can include
additional metadata for future extensions:
+While the basic requirement is just the `target` field, your API can include
additional metadata for future extensions:
```json
-{
- "targets": [
- "192.168.1.10:8080"
- ],
- "labels": {
- "env": "production",
- "version": "1.0.0"
+[
+ {
+ "target": [
+ "192.168.1.10:8080"
+ ],
+ "labels": {
+ "env": "production",
+ "version": "1.0.0"
+ }
}
-}
+]
```
-Note: Currently, only the `targets` field is used for service discovery, but
future versions may support using label information.
+Note: Currently, only the `target` field is used for service discovery, but
future versions may support using label information.
### API Implementation Examples
@@ -197,16 +203,16 @@ Note: Currently, only the `targets` field is used for
service discovery, but fut
public class ServiceDiscoveryController {
@GetMapping("/services")
- public Map<String, Object> getServices() {
- List`<String>` targets = Arrays.asList(
+ public List<Map<String, Object>> getServices() {
+ List<String> targets = Arrays.asList(
"192.168.1.10:8080",
"192.168.1.11:8080",
"192.168.1.12:8080"
);
Map<String, Object> response = new HashMap<>();
- response.put("targets", targets);
- return response;
+ response.put("target", targets);
+ return Collections.singletonList(response);
}
}
```
@@ -221,8 +227,8 @@ app.get('/api/services', (req, res) => {
'192.168.1.12:8080'
];
- res.json({
- targets: targets
- });
+ res.json([{
+ target: targets
+ }]);
});
```
diff --git
a/home/i18n/zh-cn/docusaurus-plugin-content-docs/current/help/http_sd.md
b/home/i18n/zh-cn/docusaurus-plugin-content-docs/current/help/http_sd.md
index 20f3830e92..35f4bec22c 100644
--- a/home/i18n/zh-cn/docusaurus-plugin-content-docs/current/help/http_sd.md
+++ b/home/i18n/zh-cn/docusaurus-plugin-content-docs/current/help/http_sd.md
@@ -18,21 +18,23 @@ HTTP 服务发现允许 HertzBeat 通过调用您的自定义 HTTP API 来发现
您需要提供或开发一个满足以下要求的 HTTP API:
1. **HTTP 方法**:支持 GET 请求
-2. **响应格式**:返回 JSON 格式数据
-3. **响应结构**:必须包含 `targets` 字段,该字段为字符串数组,每个字符串是一个服务实例地址,格式为 `host:port`
+2. **响应格式**:返回 JSON 格式数组
+3. **响应结构**:必须是数组格式,每个元素包含 `target` 字段(注意是单数),该字段为字符串数组,每个字符串是一个服务实例地址,格式为
`host:port`
4. **可访问性**:该 API 必须可从 HertzBeat 访问
#### API 响应示例
```json
-{
- "targets": [
- "192.168.1.101:8080",
- "192.168.1.102:8080",
- "192.168.1.103:8080",
- "api.example.com:443"
- ]
-}
+[
+ {
+ "target": [
+ "192.168.1.101:8080",
+ "192.168.1.102:8080",
+ "192.168.1.103:8080",
+ "api.example.com:443"
+ ]
+ }
+]
```
### 配置参数
@@ -81,13 +83,15 @@ HTTP 服务发现允许 HertzBeat 通过调用您的自定义 HTTP API 来发现
- **响应**:
```json
- {
- "targets": [
- "10.0.1.10:8080",
- "10.0.1.11:8080",
- "10.0.1.12:8080"
- ]
- }
+ [
+ {
+ "target": [
+ "10.0.1.10:8080",
+ "10.0.1.11:8080",
+ "10.0.1.12:8080"
+ ]
+ }
+ ]
```
配置示例:
@@ -134,7 +138,7 @@ HTTP 服务发现允许 HertzBeat 通过调用您的自定义 HTTP API 来发现
### 注意事项
-- **响应格式**:API 响应必须是 JSON 格式且包含 `targets` 字段(字符串数组)
+- **响应格式**:API 响应必须是 JSON 数组格式,每个元素包含 `target` 字段(注意是单数,字符串数组)
- **地址格式**:每个目标地址应为 `host:port` 格式,例如:
- `192.168.1.100:8080`
- `api.example.com:443`
@@ -171,21 +175,23 @@ HTTP 服务发现允许 HertzBeat 通过调用您的自定义 HTTP API 来发现
#### 包含额外元数据的响应
-虽然基本要求只是 `targets` 字段,但您的 API 可以包含额外的元数据以供未来扩展使用:
+虽然基本要求只是 `target` 字段,但您的 API 可以包含额外的元数据以供未来扩展使用:
```json
-{
- "targets": [
- "192.168.1.10:8080"
- ],
- "labels": {
- "env": "production",
- "version": "1.0.0"
+[
+ {
+ "target": [
+ "192.168.1.10:8080"
+ ],
+ "labels": {
+ "env": "production",
+ "version": "1.0.0"
+ }
}
-}
+]
```
-注意:目前仅使用 `targets` 字段进行服务发现,但未来版本可能支持使用标签信息。
+注意:目前仅使用 `target` 字段进行服务发现,但未来版本可能支持使用标签信息。
### API 实现示例
@@ -197,16 +203,16 @@ HTTP 服务发现允许 HertzBeat 通过调用您的自定义 HTTP API 来发现
public class ServiceDiscoveryController {
@GetMapping("/services")
- public Map<String, Object> getServices() {
- List`<String>` targets = Arrays.asList(
+ public List<Map<String, Object>> getServices() {
+ List<String> targets = Arrays.asList(
"192.168.1.10:8080",
"192.168.1.11:8080",
"192.168.1.12:8080"
);
Map<String, Object> response = new HashMap<>();
- response.put("targets", targets);
- return response;
+ response.put("target", targets);
+ return Collections.singletonList(response);
}
}
```
@@ -221,8 +227,8 @@ app.get('/api/services', (req, res) => {
'192.168.1.12:8080'
];
- res.json({
- targets: targets
- });
+ res.json([{
+ target: targets
+ }]);
});
```
diff --git
a/home/i18n/zh-cn/docusaurus-plugin-content-docs/version-1.7.x/help/http_sd.md
b/home/i18n/zh-cn/docusaurus-plugin-content-docs/version-1.7.x/help/http_sd.md
index 20f3830e92..35f4bec22c 100644
---
a/home/i18n/zh-cn/docusaurus-plugin-content-docs/version-1.7.x/help/http_sd.md
+++
b/home/i18n/zh-cn/docusaurus-plugin-content-docs/version-1.7.x/help/http_sd.md
@@ -18,21 +18,23 @@ HTTP 服务发现允许 HertzBeat 通过调用您的自定义 HTTP API 来发现
您需要提供或开发一个满足以下要求的 HTTP API:
1. **HTTP 方法**:支持 GET 请求
-2. **响应格式**:返回 JSON 格式数据
-3. **响应结构**:必须包含 `targets` 字段,该字段为字符串数组,每个字符串是一个服务实例地址,格式为 `host:port`
+2. **响应格式**:返回 JSON 格式数组
+3. **响应结构**:必须是数组格式,每个元素包含 `target` 字段(注意是单数),该字段为字符串数组,每个字符串是一个服务实例地址,格式为
`host:port`
4. **可访问性**:该 API 必须可从 HertzBeat 访问
#### API 响应示例
```json
-{
- "targets": [
- "192.168.1.101:8080",
- "192.168.1.102:8080",
- "192.168.1.103:8080",
- "api.example.com:443"
- ]
-}
+[
+ {
+ "target": [
+ "192.168.1.101:8080",
+ "192.168.1.102:8080",
+ "192.168.1.103:8080",
+ "api.example.com:443"
+ ]
+ }
+]
```
### 配置参数
@@ -81,13 +83,15 @@ HTTP 服务发现允许 HertzBeat 通过调用您的自定义 HTTP API 来发现
- **响应**:
```json
- {
- "targets": [
- "10.0.1.10:8080",
- "10.0.1.11:8080",
- "10.0.1.12:8080"
- ]
- }
+ [
+ {
+ "target": [
+ "10.0.1.10:8080",
+ "10.0.1.11:8080",
+ "10.0.1.12:8080"
+ ]
+ }
+ ]
```
配置示例:
@@ -134,7 +138,7 @@ HTTP 服务发现允许 HertzBeat 通过调用您的自定义 HTTP API 来发现
### 注意事项
-- **响应格式**:API 响应必须是 JSON 格式且包含 `targets` 字段(字符串数组)
+- **响应格式**:API 响应必须是 JSON 数组格式,每个元素包含 `target` 字段(注意是单数,字符串数组)
- **地址格式**:每个目标地址应为 `host:port` 格式,例如:
- `192.168.1.100:8080`
- `api.example.com:443`
@@ -171,21 +175,23 @@ HTTP 服务发现允许 HertzBeat 通过调用您的自定义 HTTP API 来发现
#### 包含额外元数据的响应
-虽然基本要求只是 `targets` 字段,但您的 API 可以包含额外的元数据以供未来扩展使用:
+虽然基本要求只是 `target` 字段,但您的 API 可以包含额外的元数据以供未来扩展使用:
```json
-{
- "targets": [
- "192.168.1.10:8080"
- ],
- "labels": {
- "env": "production",
- "version": "1.0.0"
+[
+ {
+ "target": [
+ "192.168.1.10:8080"
+ ],
+ "labels": {
+ "env": "production",
+ "version": "1.0.0"
+ }
}
-}
+]
```
-注意:目前仅使用 `targets` 字段进行服务发现,但未来版本可能支持使用标签信息。
+注意:目前仅使用 `target` 字段进行服务发现,但未来版本可能支持使用标签信息。
### API 实现示例
@@ -197,16 +203,16 @@ HTTP 服务发现允许 HertzBeat 通过调用您的自定义 HTTP API 来发现
public class ServiceDiscoveryController {
@GetMapping("/services")
- public Map<String, Object> getServices() {
- List`<String>` targets = Arrays.asList(
+ public List<Map<String, Object>> getServices() {
+ List<String> targets = Arrays.asList(
"192.168.1.10:8080",
"192.168.1.11:8080",
"192.168.1.12:8080"
);
Map<String, Object> response = new HashMap<>();
- response.put("targets", targets);
- return response;
+ response.put("target", targets);
+ return Collections.singletonList(response);
}
}
```
@@ -221,8 +227,8 @@ app.get('/api/services', (req, res) => {
'192.168.1.12:8080'
];
- res.json({
- targets: targets
- });
+ res.json([{
+ target: targets
+ }]);
});
```
diff --git a/home/versioned_docs/version-1.7.x/help/http_sd.md
b/home/versioned_docs/version-1.7.x/help/http_sd.md
index fd29acd77d..5cd0c58f8e 100644
--- a/home/versioned_docs/version-1.7.x/help/http_sd.md
+++ b/home/versioned_docs/version-1.7.x/help/http_sd.md
@@ -18,21 +18,23 @@ HTTP Service Discovery allows HertzBeat to discover service
instances by calling
You need to provide or develop an HTTP API that meets the following
requirements:
1. **HTTP Method**: Support GET requests
-2. **Response Format**: Return JSON format data
-3. **Response Structure**: Must contain a `targets` field, which is a string
array. Each string is a service instance address in the format `host:port`
+2. **Response Format**: Return JSON array format
+3. **Response Structure**: Must be an array format, each element contains a
`target` field (note: singular), which is a string array. Each string is a
service instance address in the format `host:port`
4. **Accessibility**: The API must be accessible from HertzBeat
#### API Response Example
```json
-{
- "targets": [
- "192.168.1.101:8080",
- "192.168.1.102:8080",
- "192.168.1.103:8080",
- "api.example.com:443"
- ]
-}
+[
+ {
+ "target": [
+ "192.168.1.101:8080",
+ "192.168.1.102:8080",
+ "192.168.1.103:8080",
+ "api.example.com:443"
+ ]
+ }
+]
```
### Configuration parameter
@@ -81,13 +83,15 @@ Suppose you have a service management API:
- **Response**:
```json
- {
- "targets": [
- "10.0.1.10:8080",
- "10.0.1.11:8080",
- "10.0.1.12:8080"
- ]
- }
+ [
+ {
+ "target": [
+ "10.0.1.10:8080",
+ "10.0.1.11:8080",
+ "10.0.1.12:8080"
+ ]
+ }
+ ]
```
Configuration example:
@@ -134,7 +138,7 @@ Configuration example:
### Notes
-- **Response Format**: The API response must be in JSON format and contain a
`targets` field (string array)
+- **Response Format**: The API response must be in JSON array format, each
element contains a `target` field (note: singular, string array)
- **Address Format**: Each target address should be in the format `host:port`,
for example:
- `192.168.1.100:8080`
- `api.example.com:443`
@@ -171,21 +175,23 @@ Configuration example:
#### Response with Additional Metadata
-While the basic requirement is just the `targets` field, your API can include
additional metadata for future extensions:
+While the basic requirement is just the `target` field, your API can include
additional metadata for future extensions:
```json
-{
- "targets": [
- "192.168.1.10:8080"
- ],
- "labels": {
- "env": "production",
- "version": "1.0.0"
+[
+ {
+ "target": [
+ "192.168.1.10:8080"
+ ],
+ "labels": {
+ "env": "production",
+ "version": "1.0.0"
+ }
}
-}
+]
```
-Note: Currently, only the `targets` field is used for service discovery, but
future versions may support using label information.
+Note: Currently, only the `target` field is used for service discovery, but
future versions may support using label information.
### API Implementation Examples
@@ -197,16 +203,16 @@ Note: Currently, only the `targets` field is used for
service discovery, but fut
public class ServiceDiscoveryController {
@GetMapping("/services")
- public Map<String, Object> getServices() {
- List`<String>` targets = Arrays.asList(
+ public List<Map<String, Object>> getServices() {
+ List<String> targets = Arrays.asList(
"192.168.1.10:8080",
"192.168.1.11:8080",
"192.168.1.12:8080"
);
Map<String, Object> response = new HashMap<>();
- response.put("targets", targets);
- return response;
+ response.put("target", targets);
+ return Collections.singletonList(response);
}
}
```
@@ -221,8 +227,8 @@ app.get('/api/services', (req, res) => {
'192.168.1.12:8080'
];
- res.json({
- targets: targets
- });
+ res.json([{
+ target: targets
+ }]);
});
```
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]