Skip to content

Instantly share code, notes, and snippets.

@mklkj
Forked from ar-android/Api.java
Last active June 22, 2019 16:05
Show Gist options
  • Save mklkj/f7c1cc4ae00fdd309e1eb70d831a6dd3 to your computer and use it in GitHub Desktop.
Save mklkj/f7c1cc4ae00fdd309e1eb70d831a6dd3 to your computer and use it in GitHub Desktop.
OkHttp With RxAndroid and RxJava
fun getData(): Single<Response> {
val client = OkHttpClient()
val request = Request.Builder()
.url("https://github.com/ar-android/panfic/raw/master/Panfic/gen/com/ocit/data.json")
.get()
.addHeader("cache-control", "no-cache")
.addHeader("postman-token", "ac8311d5-3876-ea1e-53d3-85f9e397ea21")
.build()
return Single.create { emitter ->
try {
val response = client.newCall(request).execute()
emitter.onSuccess(response)
} catch (e: IOException) {
e.printStackTrace()
emitter.onError(e)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment