I have the following example path to my API -
base_url/path/{country}/path/path?from=2020-03-01T00:00:00Z&to=2020-03-02T00:00:00Z
So I need to pass 2 Date objects using the Z and T formatting and I can't really get how to format a new Kotlin Date() object into these Z and T formatting.
My current get method -
@GET("path/{country}/path/path/")
suspend fun getCountryModelByDate(
@Path("country") country: String,
@Query("from") from : String,
@Query("to") to : String
): Model
But when I try to test my method like the following -
class RemoteDataSource(private val api: Api) {
suspend fun getCountryModelByDate(): Resource<Model> {
return try {
Resource.Success(coronaVirusApi.getCovidDeathsByDeathFromCountry("italy", Date().toString(), Date().toString()))
} catch (exception: Exception) {
Resource.Exception(exception)
}
}
}
Which causes me to get the following 404 error, look at the URL that is being sent -
Response{protocol=h2, code=404, message=, url=https://api.covid19api.com/country/italy/status/deaths/?from=Tue%20Nov%2017%2010%3A47%3A30%20GMT%2B02%3A00%202020&to=Tue%20Nov%2017%2010%3A47%3A30%20GMT%2B02%3A00%202020}
So my questions are -
- How do I format a Kotlin Date object to have a Z and T format like what I need for my API?
- How can I send the formatted date into my query without it being gibrished out?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…