urlbuilder

Create and modify URLs and URL parameters easily, with a builder class.

License

License

GroupId

GroupId

io.mikael
ArtifactId

ArtifactId

urlbuilder
Last Version

Last Version

2.0.9
Release Date

Release Date

Type

Type

jar
Description

Description

urlbuilder
Create and modify URLs and URL parameters easily, with a builder class.
Source Code Management

Source Code Management

https://github.com/mikaelhg/urlbuilder

Download urlbuilder

How to add to project

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

Dependencies

test (3)

Group / Artifact Type Version
info.cukes : cucumber-java jar 1.2.5
info.cukes : cucumber-testng jar 1.2.5
org.testng : testng jar 6.11

Project Modules

There are no modules declared in this project.

Java URL builder

Build Status Coverage Status Maven Central

Create and modify URLs and URL parameters easily, with a builder class.

Builder instances are immutable, thread-safe and reusable. Every change creates a new instance.

UrlBuilder.fromString("http://www.google.com/")
    .addParameter("q", "charlie brown")
    .toString() == "http://www.google.com/?q=charlie+brown"

UrlBuilder.fromString("http://foo/h%F6pl%E4", "ISO-8859-1")
    .encodeAs("UTF-8")
    .toString() == "http://foo/h%C3%B6pl%C3%A4"

final UrlBuilder ub1 = UrlBuilder.empty()
    .withScheme("http")
    .withHost("www.example.com")
    .withPath("/")
    .addParameter("foo", "bar");

final java.net.URI uri1 = ub1.toUri();

try {
    final java.net.URI uri2 = ub1.toUriWithException();
} catch (java.net.URISyntaxException ex) {
    // handle the exception
}

final java.net.URL url1 = ub1.toUrl();

try {
    final java.net.URL url2 = ub1.toUrlWithException();
} catch (java.net.MalformedURLException ex) {
    // handle the exception
}

Todo:

  • More unit tests for corner cases. Please send in pull requests, your help is needed.

Use with Maven:

<dependencies>
    <dependency>
        <groupId>io.mikael</groupId>
        <artifactId>urlbuilder</artifactId>
        <version>2.0.9</version>
    </dependency>
</dependencies>

Versions

Version
2.0.9
2.0.8
2.0.7