示例

以下示例假设主应用运行在 http://localhost:3000。 将 BASE 替换为你的部署地址即可。

查看完整 API 参考 →

地理编码(curl)

代码
curl "http://localhost:3000/api/geocode?q=北京天安门"

地理编码(fetch)

代码
const res = await fetch(`${BASE}/api/geocode?q=${encodeURIComponent("北京天安门")}`);
const places = await res.json();
console.log(places); // [{ display_name, lat, lon, source }, ...]

路径规划(curl)

代码
curl -X POST "http://localhost:3000/api/plan-path" \
  -H "Content-Type: application/json" \
  -d '{"origin":{"lon":116.4,"lat":39.9},"dest":{"lon":121.5,"lat":31.2},"mode":"road"}'

路径规划(fetch)

代码
const res = await fetch(`${BASE}/api/plan-path`, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    origin: { lon: 116.4, lat: 39.9 },
    dest: { lon: 121.5, lat: 31.2 },
    mode: "road",
  }),
});
const { points, distanceKm } = await res.json();

知识库搜索(fetch)

代码
const res = await fetch(
  `${BASE}/api/knowledge/search?q=${encodeURIComponent("北京")}&limit=5`
);
const { query, count, results } = await res.json();

新闻 RSS(fetch)

代码
const res = await fetch(`${BASE}/api/news?feedKey=scroll&count=10`);
const { feedKey, feedLabel, items } = await res.json();

地震数据(fetch)

代码
const res = await fetch(`${BASE}/api/earthquakes?period=7d`);
const { period, points } = await res.json();

智能体对话(流式,fetch)

代码
const res = await fetch(`${BASE}/api/agent/chat?stream=true`, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    messages: [{ role: "user", content: "飞往北京" }],
  }),
});
const reader = res.body?.getReader();
const decoder = new TextDecoder();
while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  console.log(decoder.decode(value));
}