码迷,mamicode.com
首页 > Windows程序 > 详细

kylin 使用RESTful API 请求

时间:2017-04-17 22:05:19      阅读:4242      评论:0      收藏:0      [点我收藏+]

标签:user   str   关系   历史   dmi   npe   type   ges   highlight   

      目前根据Kylin的官方文档介绍,Kylin的认证是basic authentication,加密算法是Base64,在POST的header进行用户认证
我使用的用户和密码是(格式:username:password) :ADMIN:KYLIN 使用Base64编码后结果为QURNSU46S1lMSU4=
1、在Linux环境下
     curl -c cookiefile.txt -X POST -H "Authorization: Basic QURNSU46S1lMSU4="-H ‘Content-Type: application/json‘http://10.8.217.66:7070/kylin/api/user/authentication

     在执行的目录下会生成cookiefile.txt 文件,内容是:

技术分享

 

返回结果:

{
    "userDetails":{
        "password":null,
        "username":"ADMIN",
        "authorities":[
            {
                "authority":"ROLE_ADMIN"
            },
            {
                "authority":"ROLE_ANALYST"
            },
            {
                "authority":"ROLE_MODELER"
            }
        ],
        "accountNonExpired":true,
        "accountNonLocked":true,
        "credentialsNonExpired":true,
        "enabled":true
    }
}

 如果登录成功,JSESSIONID将被保存到cookie文件中; 在随后的http请求中,附加cookiefile.txt 文件就可以了,不需要每次都认证,

 相当于在浏览器下访问后,留下的cookis信息。  如:

curl -b cookiefile.txt -X PUT -H ‘Content-Type: application/json‘ -d ‘{"startTime":‘1423526400000‘, "endTime":‘1423526400‘, "buildType":"BUILD"}‘ http://<host>:<port>/kylin/api/cubes/your_cube/build
您可以在命令中提供用户名/密码选项“用户”; 请注意,这在shell历史中有密码泄露的风险
curl -X PUT --user ADMIN:KYLIN -H "Content-Type: application/json;charset=utf-8" -d ‘{ "startTime": 820454400000, "endTime": 821318400000, "buildType": "BUILD"}‘ http://<host>:<port>/kylin/api/cubes/kylin_sales/build

查询项目下的表数据

curl -X POST -H "Authorization: Basic QURNSU46S1lMSU4=" -H "Content-Type: application/json" -d ‘{ "sql":"select count(*) from TEST_KYLIN_FACT", "project":"learn_kylin" }‘http://<host>:<port>/kylin//api/query

你可能觉得这个方式不好,写这么多,没有关系,你也可以通过代码实现,使用JDBC访问方式。如果仅仅为了看数据,也可以使用PostMan来看数据。

2、POSTMAN 方式查看或者请求

首先必须知道你用什么用户名和密码去访问Kylin,所以Header信息必须要带。

   Authorization:Basic QURNSU46S1lMSU4=
   Content-Type: application/json;charset=UTF-8


 

1、查看Cube信息
get:http://10.8.217.66:7070/kylin/api/cubes?cubeName=kylin_sales_cube&limit=15&offset=0

技术分享

2、列出当前项目的表和列

技术分享

 

3、SQL 查询语句请求
post:http://10.8.217.66:7070/kylin/api/query

{
"sql":"select * from KYLIN_SALES",
"offset":0,
"limit":50000,
"acceptPartial":false,
"project":"learn_kylin"
}

4、列出所以Cubes信息
get:http://10.8.217.66:7070//kylin/api/cubes

5、GET http://10.8.217.66:7070/kylin/api/cubes/kylin_sales_cube
6、GET http://10.8.217.66:7070/kylin//api/cube_desc/{cubeName}


参考详见:
http://kylin.apache.org/docs20/howto/howto_use_restapi.html#build-cube
http://kylin.apache.org/docs20/howto/howto_build_cube_with_restapi.html




kylin 使用RESTful API 请求

标签:user   str   关系   历史   dmi   npe   type   ges   highlight   

原文地址:http://www.cnblogs.com/qinpengming/p/6724902.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!