-
Notifications
You must be signed in to change notification settings - Fork 369
Proposal: Add Uri/Url Type to Kotlin Standard Library #415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
iseki0
wants to merge
5
commits into
Kotlin:master
Choose a base branch
from
iseki0:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
262ed8f
Add uri.md
iseki0 0375f03
reformat sample code
iseki0 1a7f3a2
Improve the representation and fill the WIP section
iseki0 371d521
Remove the unused build() function call
iseki0 5ae6889
Merge branch 'Kotlin:master' into master
iseki0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Proposal: Add URI Type to Kotlin Standard Library | ||
|
||
**Author**: iseki zero | ||
**Status**: Pending | ||
**Submitted**: 2025-03-09 | ||
|
||
--- | ||
|
||
## Summary | ||
|
||
This proposal advocates for introducing a first-class `URI` type to the Kotlin Standard Library. | ||
|
||
URIs are a **well-established standard** ([RFC 3986]) for identifying resources, forming the foundation of modern web protocols like HTTP and essential concepts like URLs. A standardized `URI` type would unify resource handling across Kotlin platforms, enable safer and more expressive APIs for future libraries (e.g., HTTP clients), and resolve inconsistencies caused by platform-specific implementations. | ||
|
||
## Motivation | ||
|
||
Since URI is not required to refer an accessible resources, many and many libraries use URIs to represent some identifier. | ||
|
||
Not only in HTTP access(URLs), such as [package-url](https://github.com/package-url) is also an valid URI. | ||
|
||
And, if you don't care use-cases, the data-uri is also an URI([RFC 2397]). | ||
|
||
### Current Issues | ||
|
||
- On JVM platform we have `java.net.URI`. But: | ||
- The behaviors is exactly following the [RFC 3986], but the cross language supports is broken. In other words, it doesn't implement [RFC 3987]. | ||
- It's not following the Kotlin style, such as lacks of null-safety. | ||
- On JavaScript platform we have no standarized type, but we have tons of 3rd-library, the ecosystem is fragmentized. | ||
- All of them are harmful to Kotlin Multiplatform. | ||
|
||
### Goals | ||
|
||
- Provides a standarized, cross-platform, consistent type to represents URI, following [RFC 3986], even [RFC 3987]. | ||
- Provides a way to easily building, parsing it. | ||
- Provides interopbility with `java.net.URI`. | ||
- All of them will lay the foundation for future features in Kotlin Multiplatform. | ||
|
||
## Description | ||
|
||
```kotlin | ||
fun main() { | ||
val parsedURI = URI("https://example.org/kotlin/multiplatform") | ||
val builtURI = buildURI { | ||
schema = "https" | ||
host = "example.org" | ||
path { | ||
append("kotlin") | ||
append("multiplatform") | ||
} | ||
// other representation of path-adder... | ||
} | ||
} | ||
``` | ||
|
||
## Sample implementation | ||
iseki0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
WIP | ||
|
||
|
||
[RFC 3986]: https://datatracker.ietf.org/doc/html/rfc3986 "Uniform Resource Identifier (URI): Generic Syntax" | ||
|
||
[RFC 3987]: https://datatracker.ietf.org/doc/html/rfc3987 "Internationalized Resource Identifiers (IRIs)" | ||
|
||
[RFC 2397]: https://datatracker.ietf.org/doc/html/rfc2397 "The \"data\" URL scheme" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.