17

Requirements

  • generic query language that can be used in GET requests to collection resources in REST api to filter the set of resources returned
  • queries passed in via a "standard" query language and sent over HTTP as request parameter(s) - .e.g /someresource?query=...... or /someresource?a.b.c=2
  • SQL queries constructed at runtime on the server
  • tight integration with jpa, spring-data, spring-data-rest - the less code the better.
  • nested resource and attribute paths available for queries
  • support for complex operands - EQUALS, GREATER_THAN, LESS_THAN, NEGATION, LIKE, AND, OR, NOT, IN

E.g. resourceA.attribute1 = "CAT" AND resourceA.subResourceB.attribute2 >= 42 AND resourceA.attribute3 IN ("WHIZ","BANG")

I've investigated four solutions - each getting closer to the goal. Is there some other solution I haven't found or is there no such complete solution out of the box - is the answer to build upon the "REST query language with RSQL" outlined below?

1) spring-data-rest queries

There is plenty of support in spring data for developing complex queries in code, however this requires the developer to be aware of the structure of queries beforehand and to construct the code accordingly. https://docs.spring.io/spring-data/rest/docs/current/reference/html/#repository-resources.query-method-resource

2) spring-data, spring-data-rest, query-dsl

http://www.baeldung.com/rest-api-search-querydsl-web-in-spring-data-jpa

+ve An excellent fit - thoroughly capable solution with almost zero coding out of the box

+ve deeply nested queries can be constructed and the server generates correct SQL on the fly.

-ve the only operator is EQUALS '=' in order to apply additional operators you need to implement QuerydslBinderCustomizer instances which once again requires the server code to be aware of the complexity of the query in advance.

https://docs.spring.io/spring-data/commons/docs/current/api/org/springframework/data/querydsl/binding/QuerydslBinderCustomizer.html

3) Baeldung - "building a rest query language"

http://www.baeldung.com/spring-rest-api-query-search-language-tutorial

+ve - getting closer to generic query language

-ve - feels like a demo / POC

4) REST Query Language with RSQL

http://www.baeldung.com/rest-api-search-language-rsql-fiql

+ve - feels like a more complete Query language & associated parser

-ve - unsure of spring integration

Nathan Coast
  • 171
  • 1
  • 8

1 Answers1

1

There is no generic REST query language for JPA. What you've identified seems to be what is out there, however the low recent activity on querydsl and rsql suggests that you should use caution when adopting them. You will most likely have to support additional changes yourself by forking the projects, especially 5 years from now when for sure the author has moved on to other things.

Some other interesting links:

5) Use annotations to dynamically build queries

dukethrash
  • 1,449
  • 4
  • 15
  • 25