I need to create in a REST API client some classes to handle the (de)serialization of the data and I'm not use how to name the classes in a meaningful way.
For example, with the following API
GET /User
POST /Message
I thought of using this structure:
package com.example.model
import kotlinx.serialization.Serializable
object User {
@Serializable
data class Response(
val username: String,
val fullName: String
)
}
object Message {
@Serializable
data class Request(
val title: String,
val message: String
)
@Serializable
data class Response(
val status: Int
)
}
But than I don't know how to handle something like this (let's assume that all the request and response have a different structure):
GET /User
POST /Message
DELETE /Message
I thought of something like this:
object UserGet { ... }
object MessagePost { ... }
object MessageDelete { ... }
But then I don't know how to deal with this:
GET /User
GET /User/{userId}
GET /User/{userId}/AllMessages
POST /Message
DELETE /Message
Is there a convention for this use case? How is this usually handled on the server side?