nGrinder 3.3提供了40多个REST api。最初,他们被开发成运行nGrinder作为基础架构。最近我们的一个合作伙伴开始创建游戏云,他们想运行nGrinder,但使用他们自己的UI。nGrinder 3.3 REST api支持这个场景。我们的REST API集允许其他系统控制nGrinder的所有特性,包括用户管理、代理管理、脚本管理、性能测试管理。甚至系统配置。
您可以首先查看 REST API/QuickStart,了解它的工作原理。
URL和方法
nGrinder REST APIs 通常为每个可用url提供"/api"上下文路径访问。例如,压力测试相关的URL使用 http://hostname/perftest/,那么压力测试的REST API地址使用 http://hostname/perftest/api/。当{id}添加到路径末尾时,就像这样 http://hostname/perftest/api/10,这意味着“对指定id的元素做处理”。根据使用的HTTP方法不同,URL执行不同的任务。
URL | HTTP Method | Description |
---|---|---|
http://hostname/{topic}/api/ | GET | 获取元素列表 |
http://hostname/{topic}/api?ids={id,id} | GET | 得到给定的元素 |
http://hostname/{topic}/api/{kind}?ids={id,id} | GET | 获取给定元素的特定信息 |
http://hostname/{topic}/api/{id} | GET | 得到给定的元素 |
http://hostname/{topic}/api/{id}/{kind} | GET | 获取给定元素的特定信息 |
http://hostname/{topic}/api/ | POST | 创建元素 |
http://hostname/{topic}/api/{id} | PUT | 修改元素 |
http://hostname/{topic}/api?ids={id,id} | PUT | 修改给定的元素 |
http://hostname/{topic}/api?action={action}&ids={id,id} | PUT | 对给定的元素做一些操作 |
http://hostname/{topic}/api/{id}?action={action} | PUT | 对给定的元素做一些操作 |
http://hostname/{topic}/api/{id} | DELETE | 删除元素 |
http://hostname/{topic}/api?ids={id,id} | DELETE | 删除给定的元素 |
身份验证
要使用nGrinder REST API,它应该使用HTTP基本认证。例如,当通过REST API访问当前压力测试列表时,可以像下面这样调用api。
# when using curl
curl --user admin:admin http://ngrinder-hostname/perftest/api
# when using wget
wget --http-user=admin --http-passwd=admin http://ngrinder-hostname/perftest/api
参数
在调用api时,也可以传递参数。例如,当您使用压力测试列表时
# 当每个页面大小为10时,获取压力测试列表的第二页
http://hostname/perftest/api?page=2&size=10
使用GET方法,您可以提供页面和大小参数,以便检索给定的压力测试列表数量。在使用DELETE方法时,应将参数作为URL参数提供。对于POST、PUT,应该将它们作为表单变量发送。
API详细描述
您可以找到每个api的详细描述。
更多内容请查看: 压力测试平台(nGrinder)入门到精通教程
网友评论