Thanks, that resolved the problem. I’m also in need of assistance creating HTTP requests. I need to know how to create both constant and dynamic headers, as well as handling body data. I need the body data to be in JSON format when it reaches the server. Is GSON the standard kotlin data format?
How would I call that? Would that accept a header as a parameter where I call it?
Lastly, I need to store data (mainly data from HTTP requests), both in state across Composables and more constant data that is saved even if the app is closed. Any guidance would be greatly appreciated. Thank you.
I don’t know what you mean by this… as in a header with a constant value, and a header with a value that can be set at runtime? IE, the “Accept” header is always “application/json”, but the “Authorization” header has a value provided at runtime?
As far as I’m aware, GSON is a library created by Google for serializing and deserializing JSON data. JSON is a data format, and there are various libraries for handling JSON serialization and deserialization. I believe the most popular library for Java is Jackson, but GSON is a perfectly fine alternative. Any library is fine, as long as it correctly serialises and deserializes. After that, it’s personal preference.
This is a specific question about this library, and I know nothing about this library. I’ve never heard of it before. However, if I was to guess, I would guess that the value in the annotation is the name of the header, and the value of the parameter is the value of the header. For example, if you wanted to provide an Authorization header with a JWT, you’d do it like so: suspend fun authenticate(@Header(value = "Authorization") jwt: String): Call<String>
If you want to store data in a way that persists even when your app is closed, you need a database. (Or just write plain text files to the device) I know very little about Android development, so I can’t really help here, I’m sorry. As for storing it as state in Composables… I think that Composable functions don’t store state, they just remember state and then recompose if it changes. I think if you want to store state, you just create a variable, same as you would for any data, and then pass that variable into your Composable function. As long as that variable exists and holds data, the Composable function will be able to read the data from that variable. If the value of that variable changes, the Composable function will be called again due to a state change.