Virola Web API
Web API 的当前版本非常基础,因为我们决定在收到第一个工作请求后立即开始发布它。
可以使用 curl 命令进行测试 Web API 调用。
发送 Web API 请求需要 Web API 访问令牌。
要获取 Web API 令牌,请使用 主菜单“工具”->“Web API 访问令牌”
该令牌会将您的用户配置文件与您进行的 Web API 调用绑定在一起, 因此所有调用都将代表您执行。
注意! 生成新令牌后,您之前生成的令牌将停止工作。
需要聊天室 ID 才能发送聊天消息。
要获取聊天室 ID,请右键单击房间列表中的房间,然后在打开的上下文菜单顶部查看其编号。
Web API Requests
Get server health information
curl -k -X GET \ -H "Authorization: Bearer TOKEN" \ https://HOST:PORT/api/v1/server-health
Send a text message into the room
curl -k -X POST \
-H "Authorization: Bearer TOKEN" \
https://HOST:PORT/api/v1/rooms/ROOM_ID/text-messages \
-d "{\"content\":\"Hello, World\"}"
You can also use the javascript language to access wabapi, as shown in the following example:
<html>
<body>
<script>
var req = new XMLHttpRequest();
req.onreadystatechange = function() {
if (req.readyState == 4 && req.status == 200)
document.write("<pre>" + req.responseText + "</pre>");
}
req.open("GET", "https://HOST:PORT/api/v1/server-health", true);
req.setRequestHeader("Authorization", "Bearer TOKEN");
req.send(null);
</script>
</body>
</html>