导入
每日指数
学习如何获取所有每日指数及其元数据。
1http://dataservice.accuweather.com/indices/v1/daily
| 参数 | 类型 | 分类 | 描述 |
|---|---|---|---|
| API_KEY | string | 必需 | 这是我们的API密钥。这是一个查询参数。 |
| language | string | 可选 | 返回结果所使用的语言。默认值为 en-us。这是一个查询参数。 |
1// 在此处导入库 2import fetch from "node-fetch"; 3 4// 在此处定义API密钥 5const API_KEY = '{{API_KEY}}'; 6 7// 在此处定义端点URL 8const url = new URL(`http://dataservice.accuweather.com/indices/v1/daily`); 9 10// 在此处定义头参数 11const headerParameters = { 12 contentType: 'application/json', 13}; 14 15// 在此处定义查询参数 16const queryParameters = new URLSearchParams({ 17 apikey: API_KEY, 18}); 19 20// 设置API调用选项 21const options = { 22 method: 'GET', 23 headers: headerParameters, 24}; 25 26// 用于发起API调用的函数 27async function getAllIndices() { 28 try { 29 url.search = queryParameters; 30 const response = await fetch(url, options); 31 32 // 自定义函数,用于打印API响应 33 printResponse(response); 34 } catch (error) { 35 // 自定义函数,用于打印错误信息 36 printError(error); 37 } 38} 39 40// 调用函数以发起API调用 41getAllIndices();
| 参数 | 类型 | 描述 |
|---|---|---|
| Name | string | 这是指数的名称。 |
| ID | integer | 这是指数的ID。该值可能为 null。 |
| Ascending | boolean | 这是指数值的排序方式。如果设置为 true,则最佳值为 10,最差值为 0;如果为 false,则最佳值为 0,最差值为 10。 |
| Description | string | 这是指数类型的描述。 |