rest-query-engine

A library for parsing rsql queries into database queries for a REST API.

License

License

MIT
GroupId

GroupId

com.github.rutledgepaulv
ArtifactId

ArtifactId

rest-query-engine
Last Version

Last Version

0.7.1
Release Date

Release Date

Type

Type

jar
Description

Description

rest-query-engine
A library for parsing rsql queries into database queries for a REST API.
Project URL

Project URL

http://github.com/rutledgepaulv/rest-query-engine
Source Code Management

Source Code Management

http://github.com/rutledgepaulv/rest-query-engine

Download rest-query-engine

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.rutledgepaulv/rest-query-engine/ -->
<dependency>
    <groupId>com.github.rutledgepaulv</groupId>
    <artifactId>rest-query-engine</artifactId>
    <version>0.7.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.rutledgepaulv/rest-query-engine/
implementation 'com.github.rutledgepaulv:rest-query-engine:0.7.1'
// https://jarcasting.com/artifacts/com.github.rutledgepaulv/rest-query-engine/
implementation ("com.github.rutledgepaulv:rest-query-engine:0.7.1")
'com.github.rutledgepaulv:rest-query-engine:jar:0.7.1'
<dependency org="com.github.rutledgepaulv" name="rest-query-engine" rev="0.7.1">
  <artifact name="rest-query-engine" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.rutledgepaulv', module='rest-query-engine', version='0.7.1')
)
libraryDependencies += "com.github.rutledgepaulv" % "rest-query-engine" % "0.7.1"
[com.github.rutledgepaulv/rest-query-engine "0.7.1"]

Dependencies

compile (3)

Group / Artifact Type Version
cz.jirutka.rsql : rsql-parser jar 2.1.0
com.github.rutledgepaulv : q-builders jar 1.5
org.springframework : spring-core jar 4.3.1.RELEASE

test (3)

Group / Artifact Type Version
org.springframework.data : spring-data-mongodb jar 1.9.2.RELEASE
org.elasticsearch : elasticsearch jar 2.3.4
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

Build Status Coverage Status Maven Central

Rest Query Engine

A library for adding arbitrarily flexible querying to any java API. Almost all APIs deal with some set of predefined models which they expose via various endpoints. You shouldn't have to create your own mechanisms for querying against collections of these models and then figuring out how to make that query work against wherever you're storing it.

This common problem is where RQE comes in. Using RQE you send your queries across HTTP as a simple query parameter using the so-simple-you-feel-stupid query language rsql. This library handles everything necessary to parse that incoming query, convert the various arguments in the query into the type that will actually appear in the database, and build an intermediate query tree that can be visited to produce a query for any number of backends.

Modular

Pretty much all of the components involved to parse, traverse, and convert all use pluggable implementations. As this library matures I'll document all the extension points and why you might use them.

Backends

This library builds queries into the intermediate form understood by q-builders. This means that any backend which is supported via q-builders is also supported by this library. Currently those include:

  • Java Predicate
  • RSQL Query String
  • Elasticsearch QueryBuilder
  • Spring Data Mongodb Criteria

Client Side

Do you provide a Java-based SDK for your API? Or do you send real rest requests in your test suite? Then you'll probably be interested in using q-builders on the client side too. Since RSQL is a supported target of the intermediate representation you can use it to construct your queries for the API in a type and typo safe way.

Usage

private QueryConversionPipeline pipeline = QueryConversionPipeline.defaultPipeline();


@Test
public void mongo() {

    Condition<GeneralQueryBuilder> condition = pipeline.apply("firstName==Paul;age==30", User.class);
    Criteria query = condition.query(new MongoVisitor());

}


@Test
public void elasticsearch() {

    Condition<GeneralQueryBuilder> condition = pipeline.apply("firstName==Paul;age==30", User.class);
    QueryBuilder query = condition.query(new ElasticsearchVisitor());

}


@Test
public void predicate() {

    Condition<GeneralQueryBuilder> condition = pipeline.apply("firstName==Paul;age==30", User.class);
    Predicate<User> predicate = condition.query(new PredicateVisitor<>());

}

Installation

Release Versions

<dependencies>
    <dependency>
        <groupId>com.github.rutledgepaulv</groupId>
        <artifactId>rest-query-engine</artifactId>
        <version>0.7.1</version>
    </dependency>
</dependencies>

Snapshot Version

<dependencies>
    <dependency>
        <groupId>com.github.rutledgepaulv</groupId>
        <artifactId>rest-query-engine</artifactId>
        <version>0.7.2-SNAPSHOT</version>
    </dependency>
</dependencies>


<repositories>
    <repository>
        <id>ossrh</id>
        <name>Repository for snapshots</name>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

Optional dependencies

<dependencies>
    
    <!-- only necessary if you're using the spring data mongodb criteria target type -->
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-mongodb</artifactId>
        <version>1.9.2.RELEASE</version>
    </dependency>

    <!-- only necessary if you're using the elasticsearch filter builder target type -->
    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>2.3.4</version>
    </dependency>
            
</dependencies>

License

This project is licensed under MIT license.

Versions

Version
0.7.1
0.7