All Projects → jirutka → Rsql Parser

jirutka / Rsql Parser

Parser for RSQL / FIQL – query language for RESTful APIs

Programming Languages

java
68154 projects - #9 most used programming language
groovy
2714 projects

Projects that are alternatives of or similar to Rsql Parser

Query Translator
Query Translator is a search query translator with AST representation
Stars: ✭ 165 (-64.36%)
Mutual labels:  search, parser
Laravel Api Handler
Package providing helper functions for a Laravel REST-API
Stars: ✭ 150 (-67.6%)
Mutual labels:  rest-api, search
Swagger Parser
Swagger 2.0 and OpenAPI 3.0 parser/validator
Stars: ✭ 710 (+53.35%)
Mutual labels:  rest-api, parser
Rusticsearch
Lightweight Elasticsearch compatible search server.
Stars: ✭ 171 (-63.07%)
Mutual labels:  rest-api, search
Elassandra
Elassandra = Elasticsearch + Apache Cassandra
Stars: ✭ 1,610 (+247.73%)
Mutual labels:  rest-api, search
Jkes
A search framework and multi-tenant search platform based on java, kafka, kafka connect, elasticsearch
Stars: ✭ 173 (-62.63%)
Mutual labels:  rest-api, search
Anystyle
Fast and smart citation reference parsing
Stars: ✭ 438 (-5.4%)
Mutual labels:  parser
Exifr
📷 The fastest and most versatile JS EXIF reading library.
Stars: ✭ 448 (-3.24%)
Mutual labels:  parser
Picofeed
PHP library to parse and write RSS/Atom feeds
Stars: ✭ 439 (-5.18%)
Mutual labels:  parser
Nintendoswitchrestapi
Reverse engineered REST API used in the Nintendo Switch app for iOS. Includes documentation on Splatoon 2's API.
Stars: ✭ 439 (-5.18%)
Mutual labels:  rest-api
Ionic Selectable
An Ionic-based versatile and highly customizable component that serves as a replacement to Ionic Select, and allows to search items, create items, customize the layout with templates and much more.
Stars: ✭ 459 (-0.86%)
Mutual labels:  search
Minigo
minigo🐥is a small Go compiler made from scratch. It can compile itself.
Stars: ✭ 456 (-1.51%)
Mutual labels:  parser
Gogrep
Search for Go code using syntax trees
Stars: ✭ 450 (-2.81%)
Mutual labels:  search
Lucene Solr
Apache Lucene and Solr open-source search software
Stars: ✭ 4,217 (+810.8%)
Mutual labels:  search
Tinyrb
A tiny subset of Ruby with a Lua'esc VM
Stars: ✭ 452 (-2.38%)
Mutual labels:  parser
Express Openapi Validator
🦋 Auto-validates api requests, responses, and securities using ExpressJS and an OpenAPI 3.x specification
Stars: ✭ 436 (-5.83%)
Mutual labels:  rest-api
Xmysql
xmysql is now https://github.com/nocodb/nocodb
Stars: ✭ 54 (-88.34%)
Mutual labels:  rest-api
Vscode Es7 Javascript React Snippets
Extension for Javascript/React snippets with search supporting ES7 and babel features
Stars: ✭ 435 (-6.05%)
Mutual labels:  search
Swagger Ui
Swagger UI is a collection of HTML, JavaScript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API.
Stars: ✭ 21,279 (+4495.9%)
Mutual labels:  rest-api
Form
🚂 Decodes url.Values into Go value(s) and Encodes Go value(s) into url.Values. Dual Array and Full map support.
Stars: ✭ 454 (-1.94%)
Mutual labels:  parser

= RSQL / FIQL parser Jakub Jirutka https://github.com/jirutka[@jirutka] :name: rsql-parser :version: 2.1.0 :mvn-group: cz.jirutka.rsql :gh-name: jirutka/{name} :gh-branch: master :src-base: link:src/main/java/cz/jirutka/rsql/parser

ifdef::env-github[] image:https://travis-ci.org/{gh-name}.svg?branch={gh-branch}["Build Status", link="https://travis-ci.org/{gh-name}"] image:https://coveralls.io/repos/{gh-name}/badge.svg?branch={gh-branch}&service=github["Coverage Status", link="https://coveralls.io/github/{gh-name}?branch={gh-branch}"] image:https://api.codacy.com/project/badge/grade/bd2168ab0e424e028ad6df8ff886d81a["Codacy code quality", link="https://www.codacy.com/app/{gh-name}"] image:https://maven-badges.herokuapp.com/maven-central/{mvn-group}/{name}/badge.svg["Maven Central", link="https://maven-badges.herokuapp.com/maven-central/{mvn-group}/{name}"] endif::env-github[]

RSQL is a query language for parametrized filtering of entries in RESTful APIs. It’s based on http://tools.ietf.org/html/draft-nottingham-atompub-fiql-00[FIQL] (Feed Item Query Language) – an URI-friendly syntax for expressing filters across the entries in an Atom Feed. FIQL is great for use in URI; there are no unsafe characters, so URL encoding is not required. On the other side, FIQL’s syntax is not very intuitive and URL encoding isn’t always that big deal, so RSQL also provides a friendlier syntax for logical operators and some of the comparison operators.

For example, you can query your resource like this: /movies?query=name=="Kill Bill";year=gt=2003 or /movies?query=director.lastName==Nolan and year>=2000. See <<Examples, examples>> below.

This is a complete and thoroughly tested parser for RSQL written in http://javacc.java.net[JavaCC] and Java. Since RSQL is a superset of the FIQL, it can be used for parsing FIQL as well.

== Related libraries

RSQL-parser can be used with:

It’s very easy to write a converter for RSQL using its AST. Take a look at very simple and naive converter to JPA2 in less than 100 lines of code https://gist.github.com/jirutka/42a0f9bfea280b3c5dca[here]. You may also read a http://www.baeldung.com/rest-api-search-language-rsql-fiql[blog article about RSQL] by https://github.com/eugenp[Eugen Paraschiv].

== Grammar and semantic

The following grammar specification is written in EBNF notation (http://www.cl.cam.ac.uk/~mgk25/iso-14977.pdf[ISO 14977]).

RSQL expression is composed of one or more comparisons, related to each other with logical operators:

  • Logical AND : ; or and
  • Logical OR : , or or

By default, the AND operator takes precedence (i.e. it’s evaluated before any OR operators are). However, a parenthesized expression can be used to change the precedence, yielding whatever the contained expression yields.


input = or, EOF; or = and, { "," , and }; and = constraint, { ";" , constraint }; constraint = ( group | comparison ); group = "(", or, ")";

Comparison is composed of a selector, an operator and an argument.


comparison = selector, comparison-op, arguments;

Selector identifies a field (or attribute, element, …) of the resource representation to filter by. It can be any non empty Unicode string that doesn’t contain reserved characters (see below) or a white space. The specific syntax of the selector is not enforced by this parser.


selector = unreserved-str;

Comparison operators are in FIQL notation and some of them has an alternative syntax as well:

  • Equal to : ==
  • Not equal to : !=
  • Less than : =lt= or <
  • Less than or equal to : =le= or <=
  • Greater than operator : =gt= or >
  • Greater than or equal to : =ge= or >=
  • In : =in=
  • Not in : =out=

You can also simply extend this parser with your own operators (see the <<How to add custom operators, next section>>).


comparison-op = comp-fiql | comp-alt; comp-fiql = ( ( "=", { ALPHA } ) | "!" ), "="; comp-alt = ( ">" | "<" ), [ "=" ];

Argument can be a single value, or multiple values in parenthesis separated by comma. Value that doesn’t contain any reserved character or a white space can be unquoted, other arguments must be enclosed in single or double quotes.


arguments = ( "(", value, { "," , value }, ")" ) | value; value = unreserved-str | double-quoted | single-quoted;

unreserved-str = unreserved, { unreserved } single-quoted = "'", { ( escaped | all-chars - ( "'" | "" ) ) }, "'"; double-quoted = '"', { ( escaped | all-chars - ( '"' | "" ) ) }, '"';

reserved = '"' | "'" | "(" | ")" | ";" | "," | "=" | "!" | "~" | "<" | ">"; unreserved = all-chars - reserved - " "; escaped = "", all-chars; all-chars = ? all unicode characters ?;

If you need to use both single and double quotes inside a quoted argument, then you must escape one of them using \ (backslash). If you want to use \ literally, then double it as \\. Backslash has a special meaning only inside a quoted argument, not in unquoted argument.

== Examples

Examples of RSQL expressions in both FIQL-like and alternative notation:


  • name=="Kill Bill";year=gt=2003
  • name=="Kill Bill" and year>2003
  • genres=in=(sci-fi,action);(director=='Christopher Nolan',actor==*Bale);year=ge=2000
  • genres=in=(sci-fi,action) and (director=='Christopher Nolan' or actor==*Bale) and year>=2000
  • director.lastName==Nolan;year=ge=2000;year=lt=2010
  • director.lastName==Nolan and year>=2000 and year<2010
  • genres=in=(sci-fi,action);genres=out=(romance,animated,horror),director==Que*Tarantino
  • genres=in=(sci-fi,action) and genres=out=(romance,animated,horror) or director==Que*Tarantino

== How to use

Nodes are http://en.wikipedia.org/wiki/Visitor_pattern[visitable], so to traverse the parsed AST (and convert it to SQL query maybe), you can implement the provided {src-base}/ast/RSQLVisitor.java[RSQLVisitor] interface or simplified {src-base}/ast/NoArgRSQLVisitorAdapter.java[NoArgRSQLVisitorAdapter].

[source, java]

Node rootNode = new RSQLParser().parse("name==RSQL;version=ge=2.0");

rootNode.accept(yourShinyVisitor);

== How to add custom operators

Need more operators? The parser can be simply enhanced by custom FIQL-like comparison operators, so you can add your own.

[source, java]

Set operators = RSQLOperators.defaultOperators(); operators.add(new ComparisonOperator("=all=", true));

Node rootNode = new RSQLParser(operators).parse("genres=all=('thriller','sci-fi')");

== Maven

Released versions are available in The Central Repository. Just add this artifact to your project:

[source, xml, subs="verbatim, attributes"]

{mvn-group} {name} {version} ----

However if you want to use the last snapshot version, you have to add the JFrog OSS repository:

[source, xml]

jfrog-oss-snapshot-local JFrog OSS repository for snapshots https://oss.jfrog.org/oss-snapshot-local true ----

== License

This project is licensed under http://opensource.org/licenses/MIT[MIT license].

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].