uribuilder-tiny

Minimal and smart URI Builder for Java

License

License

Categories

Categories

Net
GroupId

GroupId

net.moznion
ArtifactId

ArtifactId

uribuilder-tiny
Last Version

Last Version

2.7.1
Release Date

Release Date

Type

Type

jar
Description

Description

uribuilder-tiny
Minimal and smart URI Builder for Java
Project URL

Project URL

https://github.com/moznion/uribuilder-tiny
Source Code Management

Source Code Management

https://github.com/moznion/uribuilder-tiny

Download uribuilder-tiny

How to add to project

<!-- https://jarcasting.com/artifacts/net.moznion/uribuilder-tiny/ -->
<dependency>
    <groupId>net.moznion</groupId>
    <artifactId>uribuilder-tiny</artifactId>
    <version>2.7.1</version>
</dependency>
// https://jarcasting.com/artifacts/net.moznion/uribuilder-tiny/
implementation 'net.moznion:uribuilder-tiny:2.7.1'
// https://jarcasting.com/artifacts/net.moznion/uribuilder-tiny/
implementation ("net.moznion:uribuilder-tiny:2.7.1")
'net.moznion:uribuilder-tiny:jar:2.7.1'
<dependency org="net.moznion" name="uribuilder-tiny" rev="2.7.1">
  <artifact name="uribuilder-tiny" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.moznion', module='uribuilder-tiny', version='2.7.1')
)
libraryDependencies += "net.moznion" % "uribuilder-tiny" % "2.7.1"
[net.moznion/uribuilder-tiny "2.7.1"]

Dependencies

provided (1)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.14.8

test (2)

Group / Artifact Type Version
junit : junit jar 4.11
com.google.code.findbugs : findbugs jar 3.0.0

Project Modules

There are no modules declared in this project.

uribuilder-tiny Build Status Coverage Status Maven Central javadoc.io

Minimal and smart URI builder for Java.

Synopsis

Manually use

Map<String, String> queryParameters = new HashMap<>();
queryParameters.put("hoge", "fuga");

new URIBuilderTiny()
    .setScheme("https")
    .setHost("java.example.com")
    .setPort(8080)
    .setPaths("foo", "bar")
    .appendPaths("buz", "qux")
    .setQueryParameters(queryParameters)
    .addQueryParameter("piyo", "hogera")
    .setFragment("frag")
    .build(); // => same as `new URI(https://java.example.com:8080/foo/bar/buz/qux?hoge=fuga&piyo=hogera#frag)`

With URI string as initial value

new URIBuilderTiny("https://java.example.com/foo/bar")
    .setPort(8080)
    .appendPaths("buz", "qux")
    .addQueryParameter("hoge", "fuga")
    .addQueryParameter("piyo", "hogera")
    .setFragment("frag")
    .build(); // => same as `new URI(https://java.example.com:8080/foo/bar/buz/qux?hoge=fuga&piyo=hogera#frag)`

With URI instance as initial value

new URIBuilderTiny(new URI("https://java.example.com/foo/bar"))
    .setPort(8080)
    .appendPathsByString("/buz/qux")
    .addQueryParameter("hoge", "fuga")
    .addQueryParameter("piyo", "hogera")
    .setFragment("frag")
    .build(); // => same as `new URI(https://java.example.com:8080/foo/bar/buz/qux?hoge=fuga&piyo=hogera#frag)`

Raw mode (not apply URL encode)

new URIBuilderTiny()
    .setScheme("http")
    .setRawHost("h&ost.example.com")
    .setPort(8080)
    .setRawPaths(Arrays.asList("b&uz", "q&ux"))
    .appendRawPaths(Arrays.asList("f&oobar", "b&uzqux"))
    .setRawQueryParameter("h&oge", "f&uga")
    .addRawQueryParameter("p&iyo", "p&iyopiyo")
    .setRawFragment("f&rag")
    .build(); // => same as `http://h&ost.example.com:8080/b&uz/q&ux/f&oobar/b&uzqux?h&oge=f&uga&p&iyo=p&iyopiyo#f&rag`

Description

uribuilder-tiny is a minimal URI builder for Java.

URIBuilder of Apache HttpClient is a similar library. It is a major and useful library. But it has lots of methods that are not much needed, lacked some convenient methods (e.g. appendPaths) and it is a component of HttpClient so we cannot use it independently.

So I implement uribuilder-tiny to solve these frustration. This library is minimal and independent from any others.

Methods

Please see javadoc.

javadoc.io

You can put any type instance as arguments for URIBuilderTiny#setPaths() and URIBuilderTiny#appendPaths().

And you can also put any type instance as arguments of value of query parameters for URIBuilderTiny#setQueryParameters(), URIBuilderTiny#setQueryParameter(), URIBuilderTiny#addQueryParameters() and URIBuilderTiny#addQueryParameter().

It will call Object#toString() for each these instances implicitly to stringify them.

Requires

  • Java 7 or later

Author

moznion ([email protected])

License

The MIT License (MIT)
Copyright © 2015 moznion, http://moznion.net/ <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Versions

Version
2.7.1
2.7.0
2.6.1
2.6.0
2.5.0
2.4.0
2.3.0
2.2.0
2.1.0
2.0.3
2.0.2
2.0.1
2.0.0