RQL 是个类似于SQL的Web资源查询语言, 使用RQL可以通过一条语句, 并行地查询多个Web资源, 并且返回过滤, 转换或者合并的结果. 你可以把RQL当做一个简单, 高效的http client, 也可以用它来构建 BFF 应用, 简化你的开发.
RQL(Resource Query Language) is a web resources query syntax similar to SQL. With RQL, you can query multiple Http resources parallel, and return filtered, transformed, aggregated response in a single query statement.
It would be very easily to build BFF for microservices with RQL.
You can view Syntax Diagrams here (generated by https://github.com/bkiers/rrd-antlr4) (what's Syntax Diagram)
The antlr4 grammar is here
Statement Examples:
| Statement | Response Entity |
|---|---|
| Select * from <GET http://127.0.0.1:8080/simple-map > | {"a": "a", "b": "b"} |
| Select * from <GET http://127.0.0.1:8080/simple-map >; Select * from <GET http://127.0.0.1:8080/simple-list > |
[{"a": "a", "b": "b"} , [{"a": "a1", "b": "b1"}, {"a": "a2", "b": "b2"}]] |
| Select a from <GET http://127.0.0.1:8080/simple-map > | {"a": "a"} |
| Select a as b from <GET http://127.0.0.1:8080/simple-map > | {"b": "a"} |
| Resource a: <GET http://127.0.0.1:8080/simple-map > Select * from a |
{"a": "a", "b": "b"} |
| Parameter id: 'id' Select * from <GET http://127.0.0.1:8080/name?id=:id > |
{"id": "id", "name": "id's Name"} |
| Select * from <GET http://127.0.0.1:8080/name data id='id' > | {"id": "id", "name": "id's Name"} |
| Parameter data: '{"id":"1", "name":a}' Select * from <POST http://127.0.0.1:8080/records :data> |
{"row":1} |
| Statement | Response Entity |
|---|---|
| select * from <GET http://127.0.0.1:8080/simple-map > as r1 union select a from <GET http://127.0.0.1:8080/simple-map > as r2 union select a from <GET http://127.0.0.1:8080/simple-map > |
{"r1": {"a": "a", "b": "b"}, "r2": {"a": "a"}, "a":"a" } |
| Statement | Response Entity |
|---|---|
| select a.*, b.name from <GET http://127.0.0.1:8080/simple-list > as a join <GET http://127.0.0.1:8080/name > as b on b.id=a.a (1+N queries, N is in parallel) |
[{"a": "a1", "b": "b1", "name": "a1's Name"}, {"a": "a2", "b": "b2", "name": "as's Name"}] |
| select a.*, b.name from <GET http://127.0.0.1:8080/simple-list > as a join <GET http://127.0.0.1:8080/names > as b on b.id in a.a (1+1 queries) |
[{"a": "a1", "b": "b1", "name": "a1's Name"}, {"a": "a2", "b": "b2", "name": "as's Name"}] |
| Statement | Response Entity |
|---|---|
| Send <POST http://127.0.0.1:8080/records > | null |
You can get more examples from the JUnit test.
Maven pom.xml
<repository>
<id>ossrh</id>
<name>Sonatype OSSRH</name>
<url>https://oss.sonatype.org/content/groups/public/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<dependency>
<groupId>com.github.chenyuejie</groupId>
<artifactId>rql-java</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
Code snippet
String rql = "select id, name from <GET http://127.0.0.1:8080/simple-object>";
Statement stmt = RQLClient.getDefault().createStatement(rql);
RQLResponse resp = stmt.execute(rql);
Domain domain = resp.getEntity(Domain.class);
Assert.assertEquals(1, domain.id);
Assert.assertEquals("root", domain.name);
