Creating the comment service

To handle the comment REST APIs, we will create two HTTP requests. So we will create two POST and DELETE requests using the Retrofit annotations. Now create an interface named PostService.kt, and here is the code:

interface CommentService {
// Post comment in a post by Profile ID and Post ID
@POST("/comment/{user_id}/{post_id}")
fun postCommentByPostId(@Path("post_id") postId: Long, @Path("user_id") userId: Long,
@Query("commentText") commentText: String): Observable<Post>


// Delete comment in a post by Profile ID and Post ID
@DELETE("/comment/{user_id}/{post_id}")
fun deleteCommentByPostId(@Path("post_id") postId: Long, @Path("user_id") userId: Long,
@Query("commentText") commentText: String): Observable<Post>
}

postCommentByPostId(@Path("post_id") postId: Long, @Path("user_id") userId: Long,
@Query("commentText") commentText: String)  is a POST request function, and it submits a new comment. You need to pass the user_id, post_id, and the text.

deleteCommentByPostId(@Path("post_id") postId: Long, @Path("user_id") userId: Long,
@Query("commentText") commentText: String) is a DELETE request function, and it deletes the comment. You need to pass the user_id and post_id.

So far, all the requests have been created, and now we need to create an API service that will hit the server and fetch the JSON. 

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

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