An open API service indexing awesome lists of open source software.

https://github.com/eyolas/uri-query-builder

Helper for create query
https://github.com/eyolas/uri-query-builder

Last synced: 6 months ago
JSON representation

Helper for create query

Awesome Lists containing this project

README

          

[![Build Status][build-image]][build-url]

## Uri query builder

Helper for build the query part of uri

# Usage
Instantiate UriQueryBuilder and add params.
Use method build for build the String.

For each param :
* if the key is null or empty, builder skip the param
* value:
* if value is null, set "" to value
* if value is an instance of QueryList or QueryMap, builder loop on collection
* else String.valueof

## Simple example
```java

UriQueryBuilder builder = new UriQueryBuilder().param("test", "simpleTest");
Assert.assertEquals("?test=simpleTest", builder.build());

```

## QueryList
QueryList is an representation of query list.

QueryList has 4 type :
* NONE: No bracket and no index. ex : ?club=asse&club=psg&club=om
* BRACKET: With bracket. ex: ?club[]=asse&club[]=psg&club[]=om
* INDEXED: Indexed. ex: ?club[0]=asse&club[1]=psg&club[2]=om
* SEMICOLON: ex: ?club=asse;psg;om

example type INDEXED:
```java
List l = Arrays.asList("asse", "psg", "om");
QueryArrayList list = new QueryArrayList<>(l);
list.setQueryListType(QueryListType.INDEXED);
UriQueryBuilder builder = new UriQueryBuilder()
.param("club", list);
Assert.assertEquals("?club[0]=asse&club[1]=psg&club[2]=om", builder.build());
```

## QueryMap
QueryMap is an representation of query map.

example:
```java

QueryLinkedHashMap map = new QueryLinkedHashMap<>();
map.put("java", "java");
map.put("js", "javascript");
map.put("rb", "ruby");
map.put("coffee", "coffeescript");
UriQueryBuilder builder = new UriQueryBuilder()
.param("language", map);

Assert.assertEquals("?language[java]=java&language[js]=javascript&language[rb]=ruby&language[coffee]=coffeescript", builder.build());

```

# License

The [MIT](LICENCE) License

[build-image]: http://img.shields.io/travis/eyolas/uri-query-builder.svg?branch=master&style=flat-square
[build-url]: https://travis-ci.org/eyolas/uri-query-builder