Kotlin multiplatform Backward compatible Lemmy API
AGPL-3.0 License
A backwards compatible API for Lemmy made with Kotlin Multiplatform. Supports Lemmy 0.18+
val api = LemmyApi.getLemmyApi("voyager.lemmy.ml", auth)
api.getSite()
// Some features are version dependent, so we can check if they are supported
if(api.FF.instanceBlock()) {
api.instanceBlock()
}
// These enums can be different depending on the version of the API
api.getSupportedEntries<SortType>()
implementation("it.vercruysse.lemmyapi:lemmy-api:VERSION")
It is currently in beta, so only snapshots are available.
Add the following repository
maven { url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots") }
The intention is to provide an easy-to-use API that supports a wide range of Lemmy instances. The backwards compatibility is achieved by transforming the requests and responses to a "universal" type. And by allowing you to check if a feature is supported by the instance. That way you can change the behavior of your app depending on the instance's version.
It is a non-goal to provide a stable API. The API can change with every iteration without warning nor deprecation.
The API is backwards compatible by using the following strategy:
oldRoutes
interfacegetSupportedEntries<Type>
we can retrieve the supported entries for a given enum.To minimize the maintenance burden, many aspects have been automated.
This is done through kotlinscripts which are located in the GeneratorScripts
submodule
There is 3 main scripts:
GenTypes
: This script updates the datatypes for the set package version (ex: v0x19).GenRoutes
: This script generates templates for the routes, LemmyApiService and its implementation. It will output it to temp/
and you can copy what you need.GenMapperRoutes
: This script is a bit more complex. To prevent having to manually write all the basic transformations between datatypes of different versions.MapperGenerator
. Uncomment the annotations and build the project.GenMapperRoutes
. This will output them to the temp/
folder.Serializable
Parcelable
and Serializable