Skip to content

Instantly share code, notes, and snippets.

@timsheu
Created December 17, 2018 09:52
Show Gist options
  • Select an option

  • Save timsheu/1d27a439287e8601fce4ebb730b65862 to your computer and use it in GitHub Desktop.

Select an option

Save timsheu/1d27a439287e8601fce4ebb730b65862 to your computer and use it in GitHub Desktop.
Retrofit with RxKotlin sample
package com.nuvoton.nupowerstation
import com.nuvoton.nupowerstation.model.RequestLogin
import com.nuvoton.nupowerstation.model.ResponseLogin
import io.reactivex.Observable
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.http.Body
import retrofit2.http.HeaderMap
import retrofit2.http.POST
interface NPSWebAPIInterface {
@POST("login")
abstract fun postLogin(@Body request: RequestLogin,
@HeaderMap header: HashMap<String, String>) : Observable<ResponseLogin>
companion object Factory {
val baseUrl = "https://5x1san66yg.execute-api.us-east-1.amazonaws.com/prod/"
fun create(): NPSWebAPIInterface {
val retrofit = Retrofit.Builder()
.baseUrl(baseUrl)
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build()
return retrofit.create(NPSWebAPIInterface::class.java)
}
}
}
//interface NPSGetSTSToken{
// @POST("")
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment