#gStore-weekly | gStore最新版1.2之新增API接口详解

gStore1.2版本进一步丰富了API接口,接下来我们就逐一讲解每个接口的作用以及如何使用。我们首先启动http服务(以grpc为例),并指定服务端口号为9000:

# nohup模式启动grpc服务器,并指定启动端口为9000
$ nohup bin/grpc -p 9000 &

1、upload 文件上传

目前支持的上传文件格式为nt|ttl|n3|rdf|txt|zip,默认允许上传的最大文件为1GB。如需支持更大文件的上传,可修改conf.ini文件的upload_max_body_size值。

  • 请求URL

    http://127.0.0.1:9000/grpc/file/upload(注意这里的地址与其他api接口地址的区别)

  • 请求方式

    POST

  • 参数传递方式

    POST请求,httprequest 中的body中的form-data(要求RequestHeader参数Content-Type:multipart/form-data)

  • 参数

参数名必选类型说明
usernamestring用户名
passwordstring密码(明文)
encryptionstring为空,则密码为明文,为1表示用md5加密
fileboudary待上传的文件的二进制文件流
  • 返回值

参数名类型说明
StatusCodeint返回值代码值(具体请参考附表:返回值代码表)
StatusMsgstring返回具体信息
filepathstring上传成功后返回的相对路径地址
  • 示例

#Request Header
POST /grpc/file/upload HTTP/1.1
User-Agent: PostmanRuntime/7.35.0
Accept: */*
Cache-Control: no-cache
Postman-Token: 04f29577-f41f-4c8e-b78f-6f38a11a6468
Host: 127.0.0.1:9000
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Type: multipart/form-data; boundary=--------------------------297337150555265492824019
Content-Length: 562
#Request Body
----------------------------297337150555265492824019
Content-Disposition: form-data; name="username"
root
----------------------------297337150555265492824019
Content-Disposition: form-data; name="password"
123456
----------------------------297337150555265492824019
Content-Disposition: form-data; name="encryption"
0
----------------------------297337150555265492824019
Content-Disposition: form-data; name="file"; filename="test.nt"
<test.nt>
----------------------------297337150555265492824019--
#Response Header
HTTP/1.1 200 OK
Content-Type: application/json
Access-Control-Allow-Origin: *
Content-Length: 86
#Response Body
{"StatusCode":0, "StatusMsg":"success", "filepath": "./upload/test_20231121111041.nt"}

2、download 文件下载

目前支持的下载gStore根目录下的文件

  • 请求URL

    http://127.0.0.1:9000/grpc/file/download(注意这里的地址与其他api接口地址的区别)

  • 请求方式

    POST

  • 参数传递方式post请求方式:参数以Form表单方式传递(要求RequestHeader参数Content-Type:application/x-www-form-urlencoded)

  • 参数

参数名必选类型说明
usernamestring用户名(该用户名默认是system)
passwordstring密码(明文)
encryptionstring为空,则密码为明文,为1表示用md5加密
filepathstring待下载的文件路径(只支持下载gstore主目录及子目录下的文件)
  • 返回值

    以二进制流的形式响应

  • 示例

# curl请求,下载上一步上传的文件
$ curl -X POST http://127.0.0.1:9000/grpc/file/download -H 'Content-Type: application/json' -d '{"username":"root","password":"123456","encryption":"0","filepath":"./upload/test_20231121111041.nt"}'

#Response Header
HTTP/1.1 200 OK
Content-Type: application/octet-stream
Access-Control-Allow-Origin: *
Content-Range: bytes 0-12/12
Content-Length: 12
#Response Body
<a> <b> <c>.

3、rename 重命名

该接口可以对已经创建的数据库进行重命名,在进行重命名之前需要先卸载数据数据(调用unload接口)。

  • 请求URLhttp://127.0.0.1:9000/grpc/api

  • 请求方式GET/POST

  • 参数传递方式GET请求,参数直接以URL方式传递

    POST请求

    方式一:参数以JSON结构通过httprequestbody中的raw方式传递(要求RequestHeader参数Content-Type:application/json)

    方式二:参数以Form表单方式传递(要求RequestHeader参数Content-Type:application/x-www-form-urlencoded)

  • 参数

参数名必选类型说明
operationstring操作名称,固定值为rename
usernamestring用户名
passwordstring密码(明文)
encryptionstring为空,则密码为明文,为1表示用md5加密
db_namestring数据库名称
new_namestring数据库新名称
  • 返回值

参数名类型说明
StatusCodeint返回值代码值(具体请参考附表:返回值代码表)
StatusMsgstring返回具体信息
  • 示例

# curl请求
$ curl -X POST http://127.0.0.1:9000/grpc/api -H 'Content-Type: application/json' -d '{"operation":"rename","username":"root","password":"123456","encryption":"0","db_name":"test","new_name":"newTest"}'

# Response Body
{"StatusCode": 0, "StatusMsg": "success"}

4、stat统计系统资源

该接口将统计gStore服务当前CPU使用比例、内存使用和系统可用磁盘空间。

  • 请求URLhttp://127.0.0.1:9000/grpc/api

  • 请求方式

    GET/POST

  • 参数传递方式GET请求,参数直接以URL方式传递

    POST请求

    方式一:参数以JSON结构通过httprequestbody中的raw方式传递(要求RequestHeader参数Content-Type:application/json)

    方式二:参数以Form表单方式传递(要求RequestHeader参数Content-Type:application/x-www-form-urlencoded)

  • 参数

参数名必选类型说明
operationstring操作名称,固定值为stat
usernamestring用户名
passwordstring密码(明文)
encryptionstring为空,则密码为明文,为1表示用md5加密
  • 返回值

参数名类型说明
StatusCodeint返回值代码值(具体请参考附表:返回值代码表)
StatusMsgstring返回具体信息
cup_usagestringCPU使用比例
mem_usagestring内存使用(单位MB)
disk_availablestring可用磁盘空间(单位MB)
  • 示例

#curl请求
$ curl -X POST http://127.0.0.1:9000/grpc/api -H 'Content-Type: application/json' -d '{"operation":"stat","username":"root","password":"123456","encryption":"0","db_name":"test","new_name":"newTest"}'

#Response Body
{"StatusCode":0,"StatusMsg":"success","cup_usage":"10.596026","mem_usage":"2681.507812","disk_available": "12270"}

以上为gStore1.2中新增的API接口详解内容,如果是以ghttp启动服务,只需修改对应的URL前缀地址即可,下一篇我们将继续介绍gStore1.2的新功——如何构建一个空的数据库和如何通过多文件来构建数据库。

  • 13
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值