StreetComplete
StreetComplete copied to clipboard
Multiplatform HTTP Client (use Ktor Client)
Use a multiplatform HTTP client. Currently, we are using java.net.URL
for these.
HTTP connections in the app are used for
-
any communication with OSM servers, i.e. uploading map data, notes and gpx tracks, downloading map data, notes, user data, ...
-
querying a simple text file (
VersionIsBannedChecker
) -
communicating with an API to upload and activate photos (
StreetCompleteImageUploader
) -
querying user statistics from a simple API (
StatisticsDownloader
) -
downloading OSM user avatars (
AvatarsDownloader
) -
querying oneway traffic data from another simple API (
TrafficFlowSegmentsApi
) -
during OAuth access token negociation (
OAuthAuthorization
)
HTTP Client Requirements
-
multiplatform support for at least Java/Android and iOS
-
stable, well-tested and ideally (semi-)official / well-maintained
-
should be injectable, i.e. the http client can be passed as a (constructor) parameter to the function/class that uses it. Important in order to easily test the aforementioned classes
Below some comments on libraries I've looked at.
Note that of the candidates mentioned below, some are asynchronous clients, i.e. use coroutines, which is fine, but may necessitate more changes in the app architecture than simply replacing the java URL
stuff: The upload and download process that uses the above-mentioned HTTP APIs currently expect these things to be synchronous and manages concurrency itself.
OkHttp
OkHttp is said to have basic multiplatform support starting with 5.0, but v5.0 has been in alpha since 2021-01 and since one year, no new alpha of v5.0 has been released.
So, while OkHttp is a very very popular library, it is unknown when this ever will be stable. On the other hand, according to the current main developer, only the APIs are unstable [, not the implementation].
Ktor Client
A candidate is Ktor Client.
This seems to be a bit of a rabbit hole, because it seems to be designed to be (used as) part of a larger framework, in particular in a project where the server and client(s) basically live in the same repository and share a good portion of the code, which is not the case for our app. On the other hand, it seems to plug-in well with kotlinx-serialization (for e.g. JSON and XML), so it seems to be the more integrated solution.
The library is also featured in the Compose Multiplatform Wizard
Fuel
Another candidate is Fuel. However, it does not look to be eligible because:
- it is only multiplatform starting with version 3, which is still alpha
- little activity in repo, neither in response to a security vulnerability nor on v3 development. This does not inspire confidence that it is well-maintained
- all fields of the the HTTP response class are platform dependent (in the current alpha) - so, only multiplatform on paper.
Other
-
khttp is dead. No commit since 2020. Also, not multiplatform anyway.
-
kohttp is dead. No update since 2020. Also, not multiplatform anyway.
In general, both Ktor and OkHttp 5 seem okay, though I lean towards Ktor because OkHttp 5 is not stable yet and Ktor seems to be the solution that is more geared towards a Kotlin (MP) ecoystem.
OkHttp is said to have basic multiplatform support starting with 5.0, but v5.0 has been in alpha since 2021-01 and since one year, no new alpha of v5.0 has been released.
Version 5.0.0-alpha.12 was released on 2023-12-17, with notes starting from "We took too long to cut this release"
However, unless I configured it wrong, OkHttp 5 seems to be only multiplatform for JVM and JS(?), i.e. not native.
So it looks like the only viable option is Ktor Client