Creating the post service

According to our server, we have three 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 PostService {
@Headers("Content-Type: application/json")
@POST("/post/{profile_id}/new")
fun submitNewPost(@Path("profile_id") id: Long, @Query("text") text: String): Observable<List<Post>>


// Get all posted status
@Headers("Content-Type: application/json")
@GET("/posts")
fun getPostList(): Single<List<Post>>


// Get all posted status by Profile ID
@Headers("Content-Type: application/json")
@GET("/post/{id}")
fun getPostById(@Path("id") id: Long): Observable<Post>

}

Based on the preceding code, here is a brief description of the functions:

  • submitNewPost(@Query("id") id: Long, @Field("text") text: String) submits a new post, and to submit the new post, you need to pass the user ID and the text.
  • getPostList() gets all the posts.
  • getPostById(@Query("id") id: Long) gets a post. You need to pass a post ID.
..................Content has been hidden....................

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