tiny-uribuilder

Minimal URI Builder for Java 8

License

License

Categories

Categories

Net
GroupId

GroupId

net.moznion
ArtifactId

ArtifactId

tiny-uribuilder
Last Version

Last Version

1.2.1
Release Date

Release Date

Type

Type

jar
Description

Description

tiny-uribuilder
Minimal URI Builder for Java 8
Project URL

Project URL

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

Source Code Management

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

Download tiny-uribuilder

How to add to project

<!-- https://jarcasting.com/artifacts/net.moznion/tiny-uribuilder/ -->
<dependency>
    <groupId>net.moznion</groupId>
    <artifactId>tiny-uribuilder</artifactId>
    <version>1.2.1</version>
</dependency>
// https://jarcasting.com/artifacts/net.moznion/tiny-uribuilder/
implementation 'net.moznion:tiny-uribuilder:1.2.1'
// https://jarcasting.com/artifacts/net.moznion/tiny-uribuilder/
implementation ("net.moznion:tiny-uribuilder:1.2.1")
'net.moznion:tiny-uribuilder:jar:1.2.1'
<dependency org="net.moznion" name="tiny-uribuilder" rev="1.2.1">
  <artifact name="tiny-uribuilder" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.moznion', module='tiny-uribuilder', version='1.2.1')
)
libraryDependencies += "net.moznion" % "tiny-uribuilder" % "1.2.1"
[net.moznion/tiny-uribuilder "1.2.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
1.2.1
1.2.0
1.1.0
1.0.0