http 时序数据库 IoTDB 入门教程 实战篇①——RESTful API V2 - 八、参考
文章目录
一、前文二、配置参数三、开放端口四、ping一下五、基础鉴权六、查询接口七、写入接口八、参考
一、前文
IoTDB入门教程——导读
IoTDB的RESTful服务可用于查询、写入和管理操作,它使用OpenAPI标准来定义接口并生成框架。
IoTDB用户的业务服务器可通过RESTful接口进行数据的增删改查操作。
二、配置参数
配置文件路径:apache-iotdb-1.3.2-all-bin\conf\iotdb-datanode.propertiesRESTful服务默认是关闭的,修改enable_rest_service=true即可RESTful服务默认端口是18080,修改rest_service_port=18080即可还有更多参数用来配置RESTful服务,如下所示
####################
### REST Service Configuration
####################
# Is the REST service enabled
# enable_rest_service=false
# the binding port of the REST service
# rest_service_port=18080
# Whether to display rest service interface information through swagger. eg: http://ip:port/swagger.json
# enable_swagger=false
# the default row limit to a REST query response when the rowSize parameter is not given in request
# rest_query_default_row_size_limit=10000
# the expiration time of the user login information cache (in seconds)
# cache_expire_in_seconds=28800
# maximum number of users can be stored in the user login cache.
# cache_max_num=100
# init capacity of users can be stored in the user login cache.
# cache_init_num=10
# Is client authentication required
# client_auth=false
# SSL trust store path
# trust_store_path=""
# SSL trust store password.
# trust_store_pwd=""
# SSL timeout (in seconds)
# idle_timeout_in_seconds=50000
修改配置参数后,重启IoTDB,再netstat -nplt查看。就能看到18080端口的RESTful服务起来了。
三、开放端口
记得在服务器安全组上要开放RESTful服务的端口
四、ping一下
ping一下,看看RESTful服务能不能通
请求方式:GET请求路径:http://ip:port/ping请求示例:
五、基础鉴权
除了ping以外的接口,其他接口都需要鉴权(用户密码认证)如果没有鉴权,则会返回INIT_AUTH_ERROR
每次请求,都需要在header中添加'Authorization': 'Basic ' + base64.encode(username + ':' + password)比如,用户名:root,密码:root。则鉴权信息为Authorization: Basic cm9vdDpyb290,如下图
六、查询接口
请求方式:POST请求头:application/json请求路径:http://ip:port/rest/v2/query请求参数:
sql:必填,查询sql。row_limit:非必填,查询返回最大行数。 请求示例:
七、写入接口
请求方式:POST请求头:application/json请求路径:http://ip:port/rest/v2/nonQuery请求参数:
sql:必填,执行sql。 请求示例:
再查询一次
八、参考
RESTful服务 | IoTDB Website 拼多多帮助力入口
觉得好,就一键三连呗(点赞+收藏+关注)
参考文章