Kommons URI is a Kotlin Multiplatform Library that offers:
- parsing and serializing Uniform Resource Identifiers (RFC3986)
- support for kotlinx.serialization
- support for data URIs (RFC2397) with an appropriate URL stream handler provider registered on the JVM
This library is hosted on GitHub with releases provided on Maven Central.
-
Gradle
implementation("com.bkahlert.kommons:kommons-uri:2.8.0")
-
Maven
<dependency> <groupId>com.bkahlert.kommons</groupId> <artifactId>kommons-uri</artifactId> <version>2.8.0</version> </dependency>
// Parser
val uri = Uri.parse("https://username:password@example.com:8080/poo/par?qoo=qar&qaz#foo=far&faz")
val dataUri = Uri.parse("data:text/plain;charset=UTF-8;base64,ICEwQEF6e3x9fg")
// Extensions
val endpoint = uri / "path-segment"
// https://username:password@example.com:8080/poo/par/path-segment?qoo=qar&qaz#foo=far&faz
// Parser
val uri = URI("https://username:password@example.com:8080/poo/par?qoo=qar&qaz#foo=far&faz")
val dataUrl = URL("data:text/plain;charset=UTF-8;base64,ICEwQEF6e3x9fg")
// Extensions
val endpoint = uri / "path-segment" // same extensions on URI and URL
val decoded = dataUrl.openConnection().getInputStream().readBytes().decodeToString() // " !0@Az{|}~"
val decodedWithKotlin = dataUrl.readText() // " !0@Az{|}~"
Want to contribute? Awesome! The most basic way to show your support is to star the project or to raise issues. You can also support this project by making a PayPal donation to ensure this journey continues indefinitely!
Thanks again for your support, it's much appreciated! 🙏
MIT. See LICENSE for more details.