Is there any REST API query standard / DSL to express complex filters in GET URL?
Asked Answered
R

2

8

I am currently researching for an elegant way, for my REST API under development, to express filters for GET requests returning collections. I'd like to express queries as "http://[...]?filter=expressions", where I am going to evaluate the expressions part. I have a feeling, that a flexible approach would trigger the need for a simple Query DSL? The closest to a good formal specification I found so far is

http://www.juniper.net/techpubs/en_US/junos-space-sdk/13.1/apiref/com.juniper.junos_space.sdk.help/html/reference/Commonbehav.html#step8

I was wondering, if ANTLR is the tool to look at? But since this should be such a common necessity, I was wondering, if there is some REST API query standard DSL something available?

A bit confused greetings and thx for your input :)

Riana answered 19/2, 2015 at 23:54 Comment(3)
Afaik. there is no standard solution yet.Siphonostele
If you don't want to describe to the clients with meta-data, how to build the query structure, then you can use URI templates and something like Gil mentioned. That is the easy, but not so general way. We had a conversation about this here with others: lists.w3.org/Archives/Public/public-hydra/2014Sep/…Siphonostele
What I need today is an ODATA to QueryDSL predicate converter class. Interestingly in 2013, I needed the similar for .net https://mcmap.net/q/987744/-is-there-a-odata-query-to-linq-where-expression-odata-to-linq/413032 :DHump
S
2

I just stumbled upon QueryDSL which provides fluent builders for queries on a number of backend technologies.

I am not sure I like the idea of mapping the fluent builders directly to the query parameters but this approach is discussed in two blog posts referenced by the QueryDSL site.

Soberminded answered 6/8, 2015 at 12:21 Comment(1)
Hi Christopher, thx for the reply. We finally decided to combine QueryDSL with an self defined grammar, evaluated with an ANTLR4 generated parser. The module is work in progress and we will release it as OpenSource project, once the quality standards are fulfilled :). Funny enough we also ended up using MVEL, but let it do the work on parsed results.Riana
S
5

OData 4 (http://www.odata.org/) has a very complete query syntax and supports the E-R data model with navigation, filtering, expressions, etc. The MSFT Azure AD Graph API is based on OData. The only downside is that the complete spec is pretty deep. There are a few open source implementations, Apache Olingo (http://olingo.apache.org/) being one with support for Java clients and servers. There are others as well.

Spleenful answered 21/2, 2015 at 6:11 Comment(1)
Forgot to mention, OData is an OASIS standard (oasis-open.org), and has recently been submitted ISO/IEC JTC1.Spleenful
S
2

I just stumbled upon QueryDSL which provides fluent builders for queries on a number of backend technologies.

I am not sure I like the idea of mapping the fluent builders directly to the query parameters but this approach is discussed in two blog posts referenced by the QueryDSL site.

Soberminded answered 6/8, 2015 at 12:21 Comment(1)
Hi Christopher, thx for the reply. We finally decided to combine QueryDSL with an self defined grammar, evaluated with an ANTLR4 generated parser. The module is work in progress and we will release it as OpenSource project, once the quality standards are fulfilled :). Funny enough we also ended up using MVEL, but let it do the work on parsed results.Riana

© 2022 - 2024 — McMap. All rights reserved.