MCPcopy Index your code
hub / github.com/RutledgePaulV/rest-query-engine

github.com/RutledgePaulV/rest-query-engine @0.7.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.7.1 ↗ · + Follow
208 symbols 480 edges 36 files 8 documented · 4%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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</version>
    </dependency>
</dependencies>

Snapshot Version

<dependencies>
    <dependency>
        <groupId>com.github.rutledgepaulv</groupId>
        <artifactId>rest-query-engine</artifactId>
        <version>0.8-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>


    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-mongodb</artifactId>
        <version>1.9.2.RELEASE</version>
    </dependency>


    <dependency>
        <groupId>org.elasticsearch</groupId>
        <artifactId>elasticsearch</artifactId>
        <version>2.3.4</version>
    </dependency>

</dependencies>

License

This project is licensed under MIT license.

Extension points exported contracts — how you extend this code

ArgConverter (Interface)
A converter for taking a set of string arguments as part of a query value and converting them into the necessary types t [7 …
src/main/java/com/github/rutledgepaulv/rqe/argconverters/ArgConverter.java
StringToTypeConverter (Interface)
(no doc) [5 implementers]
src/main/java/com/github/rutledgepaulv/rqe/conversions/StringToTypeConverter.java
TriFunction (Interface)
Represents a function that accepts three arguments and produces a result. This is the three-arity specialization of {@li
src/main/java/com/github/rutledgepaulv/rqe/utils/TriFunction.java

Core symbols most depended-on inside this repo

apply
called by 38
src/main/java/com/github/rutledgepaulv/rqe/utils/TriFunction.java
convert
called by 15
src/main/java/com/github/rutledgepaulv/rqe/conversions/parsers/StringToInstantConverter.java
parse
called by 4
src/main/java/com/github/rutledgepaulv/rqe/argconverters/OperatorSpecificConverter.java
defaultPipeline
called by 4
src/main/java/com/github/rutledgepaulv/rqe/pipes/QueryConversionPipeline.java
equals
called by 4
src/main/java/com/github/rutledgepaulv/rqe/contexts/ParseTreeContext.java
getValues
called by 4
src/main/java/com/github/rutledgepaulv/rqe/contexts/ArgConversionContext.java
getPropertyPath
called by 4
src/main/java/com/github/rutledgepaulv/rqe/contexts/ArgConversionContext.java
getQueryOperator
called by 4
src/main/java/com/github/rutledgepaulv/rqe/contexts/ArgConversionContext.java

Shape

Method 163
Class 39
Enum 3
Interface 3

Languages

Java100%

Modules by API surface

src/main/java/com/github/rutledgepaulv/rqe/pipes/DefaultArgumentConversionPipe.java16 symbols
src/main/java/com/github/rutledgepaulv/rqe/contexts/ArgConversionContext.java16 symbols
src/main/java/com/github/rutledgepaulv/rqe/pipes/QueryConversionPipeline.java14 symbols
src/test/java/com/github/rutledgepaulv/rqe/testsupport/User.java13 symbols
src/test/java/com/github/rutledgepaulv/rqe/testsupport/Address.java11 symbols
src/main/java/com/github/rutledgepaulv/rqe/argconverters/ConverterChain.java10 symbols
src/test/java/com/github/rutledgepaulv/rqe/pipes/DemoCustomConversionPipeline.java9 symbols
src/main/java/com/github/rutledgepaulv/rqe/contexts/ParseTreeContext.java9 symbols
src/test/java/com/github/rutledgepaulv/rqe/testsupport/Comment.java8 symbols
src/test/java/com/github/rutledgepaulv/rqe/pipes/TestBase.java7 symbols
src/main/java/com/github/rutledgepaulv/rqe/operators/QueryOperator.java7 symbols
src/test/java/com/github/rutledgepaulv/rqe/pipes/NestedObjectTest.java6 symbols

For agents

$ claude mcp add rest-query-engine \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact