streetcomplete / StreetComplete

Easy to use OpenStreetMap editor for Android
https://streetcomplete.app
GNU General Public License v3.0
3.68k stars 342 forks source link

Multiplatform OSM API client #5410

Open westnordost opened 6 months ago

westnordost commented 6 months ago

Requires #5408 to be done first.

The OSM API is a HTTP REST API that communicates chiefly in XML. This must be ported to Kotlin multiplatform.

Currently, the Java library de.westnordost.osmapi is used for any communication with the OSM API 0.6, i.e. uploading map data, notes and gpx tracks, downloading map data, notes, user data, etc.

The dependency to osmapi must be replaced with an implementation based on

See interfaces TracksApi, MapDataApi and NotesApi

XML Parser / Writer requirements

xmlutil

There is currently one xml serializer compatible with kotlinx-serialization: io.github.pdvrieze.xmlutil. It is also mentioned in the Ktor docs, i.e. is the XML serializer/deserializer used in Ktor.

I didn't find any other multiplatform XML parsers/writers.

susrisha commented 5 months ago

I would like to pick this up. I will ping back after some basic implementation.

westnordost commented 5 months ago

This is blocked by #5408, i.e. that should be done first.

westnordost commented 5 months ago

Because, the thinking is the following:

  1. Both the access to the OSM API and the other APIs we are accessing should be done with the same library in order to both reduce the number of dependencies and to reduce the amount of brain-work to familiarize oneself with a library

  2. It would be possible to write a full kotlin multiplatform or iOS replacement of the Java library de.westnordost.osmapi instead, in a separate repository. de.westnordost.osmapi covers the whole of the OSM API. But re-implementing that library would be considerably more work than just implementing the (few) OSM API calls we actually use, plus, more continuous maintenance work, because the OSM API has been extended over the years, so the expectation is that if a kotlin multplatform or even an iOS version of that library is created, it will be maintained equally well. (And if it is not maintained, then maybe we don't even want to use it in STreetComplete, because we have had bad experiences with using libraries that were badly maintained or were stopped being maintained)

susrisha commented 5 months ago

My intention is to build an equivalent of de.westnordost.osmapi so that it can be used in multiplatform. Using Ktor client seems a viable option and that can be extended for other API calls within the project. I understand that the maintenance will take its toll but I beleive Ktor is here to stay. Only caveat we found was with the deserialization of xml. Though ktor provides a library, its only JVM compatible. With io.github.pdvrieze.xmlutil, I think it makes a better sense. Let me know if we have decided on HTTP Client

westnordost commented 4 months ago

Cool! Indeed. Yes, xmlutil should work. The only http client that is multiplatform also for native is Ktor Client, as far as I know, so the decision is to use Ktor. OkHttp 5 is only multiplatform jvm+js.

susrisha commented 4 months ago

@westnordost we started off simple in an independent repository. I gave you read access. We can move it to any other repo once its in a decent shape

westnordost commented 4 months ago

I can have a look at it when it is public, if you like, though bear in mind that I have zero experience with Ktor Client so far. The OSM API on the other hand I know inside-out.

susrisha commented 4 months ago

We have come to a decent shape on the api. We may need help in how to publish it for using in other projects. This may be a bit tricky.

westnordost commented 4 months ago

Not sure what you mean.

Java/Kotlin FOSS libraries are generally published on maven central via sonatype. If you are not sure what to write into the build gradle, I recently published a multiplatform library too, check https://github.com/westnordost/osm-opening-hours/blob/master/build.gradle.kts If I remember correctly, you need an account at sonatype to be able to publish artifacts, you'll need to read a guide for that because it is too long ago that I did that.

If it is regarding the license: Any open source license would do, permissive or LGPL, even GPLv3 would be fine.

susrisha commented 4 months ago

The code is almost ready to be made public. @westnordost need advice on the package name though. right now its com.example.osmapi . What do you suggest?

westnordost commented 4 months ago

in.susrisha.osmapi ?

Or, com..osmapi?

El 16 de febrero de 2024 11:36:44 CET, Naresh Kumar D @.***> escribió:

The code is almost ready to be made public. @westnordost need advice on the package name though. right now its com.example.osmapi . What do you suggest?

-- Reply to this email directly or view it on GitHub: https://github.com/streetcomplete/StreetComplete/issues/5410#issuecomment-1948134443 You are receiving this because you were mentioned.

Message ID: @.***>

susrisha commented 4 months ago

Its hosted under vindago org. So, we will name it com.vindago.osmapi Thanks for the suggestion

westnordost commented 4 months ago

In that case, in.vindago.osmapi would be more correct (as you don't own vindago.com)

El 16 de febrero de 2024 12:30:24 CET, Naresh Kumar D @.***> escribió:

Its hosted under vindago org. So, we will name it com.vindago.osmapi Thanks for the suggestion

-- Reply to this email directly or view it on GitHub: https://github.com/streetcomplete/StreetComplete/issues/5410#issuecomment-1948222717 You are receiving this because you were mentioned.

Message ID: @.***>

susrisha commented 4 months ago

@westnordost here is the public link to the API library. its not complete yet but its a start. https://github.com/vindagollc/osm-api/ Do have a look at the dev branch

westnordost commented 4 months ago

Ah, cool, interesting! This is actually a fork/port of the Java library, so this clears the license question, it must be licensed under the identical license as the java library. Would you add the license information, too?

I can have a more thorough look through it later. Do you prefer I create issues for everything I find, or rather one issue in which I bundle the "review". Or some other method? It would be nice if there was a way where I could easily comment on and make suggestions on single lines. Maybe make a PR from master to a new empty branch that does not contain anything yet, so everything is a diff?

From a cursory look, it looks quite complete already! I haven't looked at the code in detail, and there seem to be still some open TODOs / WIP, but the overall structure looks good! That must have been quite a lot of work!

Some thoughts: