restql 中with 参数的内容在restql 中实际上就是http request 的请求内容。按照restql 的设计
method 分为 from (get) , to (post) ,into(put) ,update (patch), delete (delete), 实际开发中,好多
团队对于from (get) 的处理可能并不是按照 rest标准的处理,我们可能需要使用to 处理

to 格式说明

  • 格式
 
to users
  with
    id = "user.id"
    username = "user.name"
    password = "super.secret"

http post 格式

POST http://some.api/users/
BODY { "id": "user.id", "username": "user.name", "password": "super.secret"

wtih 参数的格式

with 支持简单数据类型以及复杂格式(json,数组扁平处理 )

  • 支持的数据类型
- 字符串,使用双引号
- 数字,可以是浮点类型 ,科学计数不支持
- 布尔类型,true,false
- 列表类型,使用中括号包含
- key/value 数据结构,类似json
- 从其他查询引用的值,使用引号以及`.`引用,类似json 字段引用

变量引用

我们可以方便的传递参数,

  • 格式如下
from superheroes
    with
        name = $heroName
        level = $heroLevel
        powers = $heroPowers
 

对应的http 请求为

localhost:9000/run-query?heroName="Superman"&heroLevel=99&heroPowers=["flight","heat vision","super strenght"]

展开以及扁平处理

使用展开以及扁平功能,我们我们方便的进行传递参数的处理

  • 参考扩展使用
from superheroes as party
    with
        id = [1, 2, 3]

http 请求格式

GET http://some.api/superhero?id=1
GET http://some.api/superhero?id=2
GET http://some.api/superhero?id=3
  • 参考扁平处理
    使用-> 会镜像进行转换
 
        from superheroes as fused
         with
          id = [1, 2, 3] -> flatten
 

http 格式

GET http://some.api/superhero?id=1&id=2&id=3

值编码

可以对于参数参数编码(比如base64,json)

  • 参考使用
from superheroes as hero
    with
        stats = {health: 100,
                 magic: 100} -> json // encode this value as a json string
from superheroes as hero
    with
        bag = {capacity: 10} -> base64
 
 

选择返回值

使用only 我们可能选择应用需要的数据

  • 参考格式
from superheroes as hero
    with
        id = 1
    only
        name
        items
        skills.id
        skills.name
        nicknames -> matches("^Super")

说明:
其中我们可以使用match 进行进一步的数据过滤

忽略错误

有时对于数据查询的错误我们可能不太感兴趣,我们可恶意使用忽略错误

  • 参考格式
 
from products as product
from ratings
  with
    productId = product.id
  ignore-errors

请求头处理

很多时候我们基于请求头进行api 的认证处理,restql 提供了请求头参数的处理

  • 参考格式
from superheroes as hero
headers
    Authorization = "Basic user:pass"
    Accept = "application/json"
with
    id = 1

超时控制

很多时候接口响应比较慢,我们可以通过设置超时时间

  • 参考格式
from superheroes as hero
headers
    Authorization = "Basic user:pass"
    Accept = "application/json"
timeout 200
with
    id = 1

cache 请求头控制

我们可以添加cache 请求头,方便proxy 对于请求资源的cache 处理

use max-age = 600
from products

请求头

参考资料

http://docs.restql.b2w.io/#/restql/query-language?id=expanding-and-flattening

最新文章

  1. ASP.NET MVC5+EF6+EasyUI 后台管理系统(38)-Easyui-accordion+tree漂亮的菜单导航
  2. js代码生成form,解决mvc的url参数过长问题
  3. uva674 Coin Change ——完全背包
  4. sprint3(第六天)
  5. 六间房 繁星 酷我 来疯 秀吧 新浪秀 直播播放器 Live 1.2
  6. 获取数据后导出Excel
  7. SurfaceView绘图机制
  8. 常见iis错误之一
  9. 解决xtrabackup command not found no mysqld group 问题
  10. PHP 是什么
  11. How to create DB2 user function easily by DB Query Analyzer 6.03
  12. Python学习:函数式编程(lambda, map() ,reduce() ,filter())
  13. [Postman]捕获HTTP请求(14)
  14. BZOJ2561最小生成树——最小割
  15. multipath配置详细参考
  16. because there was insufficient free space available after evicting expired cache entries
  17. 单分子荧光原位杂交(smFISH)
  18. 常用的Array相关的属性和方法
  19. java 常用集合list与Set、Map区别及适用场景总结
  20. Ubuntu 安装 Zabbix 3.2详细步骤

热门文章

  1. Spring Boot Cache使用与整合
  2. SpringBoot第十七篇:定时任务
  3. linux-centos安装图解及配置IP远程连接
  4. 【前端知识体系-CSS相关】CSS布局知识强化
  5. Sitecore 十大优秀功能
  6. 34 个今年11月最受欢迎的 JavaScript 库
  7. 【LOJ#6485】LJJ 学二项式定理(单位根反演)
  8. 【题解】L 国的战斗续之多路出击 [P2129]
  9. Mysql系列(十)—— 性能分析工具profiling
  10. Go 笔记之如何防止 goroutine 泄露