Creating the profile service

According to our server, we have four HTTP requests for the profile. So we will create three HTTP requests using the Retrofit annotations. Now create an interface named ProfileService.kt, and here is the code:

 

interface ProfileService {

// New Profile registration
@Headers("Content-Type: application/json")
@POST("/profile/new")
fun registerProfile(@Body profile: Profile): Observable<Profile>

@Headers("Content-Type: application/json")
@GET("/profile/login")
fun loginProfile(@Query("username") username: String, @Query("password") password: String): Observable<Profile>

// Get All Profiles
@Headers("Content-Type: application/json")
@GET("/profiles")
fun getUserList(): Observable<List<Profile>>

// Get Profile by ID
@GET("/profile/{userId}")
fun getUserById(@Path("userId") userId: Long): Observable<Profile>
}

Based on the preceding code, here are the brief details of the functions:

  • registerProfile(@Body profile: Profile) registers a new profile. You need to pass a project object.
  • getUserList()  gets all the profiles.
  • getUserById(@Query("userId") userId: Long) gets a profile. You need to pass a user ID.

 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.82.154