REST library based on OkHttp3 and Gson

Connect to project:

  1. Add the JitPack repository to project-level build.gradle file
repositories {
	maven { url '' }
  1. Add the dependency to module-level gradle file
dependencies {
	implementation 'com.github.snk002:RestLib:Tag'

Sample usage:

class NewsRepository(private val api: SimpleRest) {

	// initially set endpoint address
	init {
	// request list of items from specified page
	suspend fun fetchNews(page: Int): List<NewsData>? =
		api.get("news").addParam("page", page).awaitData()
	// make flow with item, updated every 15 seconds
	fun getHeadNewsLine(): NewsData =

Usage with variuos return types:

class DataRepository(private val api: SimpleRest) {
	suspend fun postData(submission: MyRequest): SimpleResponse<PossibleResponses?> =
		// here is full path specified"https://domain.tld/api/submit", submission)
			// different acceptable types based on HTTP response code

// it is possible to use Any but better way is mark all acceptable types by interface
interface PossibleResponses

data class RegularExpected(
	val title: String,
	val subtitle: String,
	val value: Int
) : PossibleResponses

data class PartialSuccess(
	val title: String,
	val summary: String
) : PossibleResponses

data class DataError(
	val summary: String,
	val extra: Int
) : PossibleResponses

data class ServerError(
	val code: Int
) : PossibleResponses


View Github