Structuring the request model

The client app passes the raw JSON in the body to the post request. All modern client apps use the object mapper libs, which convert the model to JSON.

Our request model should look like this:

data class RequestPoll(        val pollQuestion: String,        val pollOptions: Array<String>)

For now, we are avoiding other member data, such as the user ID; you can find this in the main source code.

Let's assume that the request is coming as a raw JSON in the body of a post request. We will read that body content from the request and convert it back to the model. 

We will also generate one ID, which we store on our side as a unique key to that poll.

A function for generating a random ID can look as the following:

fun getRandomPollId ...

Get Hands-On Serverless Applications with Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.