I have a plain old java-library gradle module. In this module I'm making use of mockhttpserver from okhttp and I'm just hardcoding responses to api calls. Everything is working great.
I have this
path == "/api/myendpoint" -> {
return MockResponse()
.setResponseCode(200)
.setBody(
"""
{"status":0,"message":"SUCCESS"}
""".trimIndent())
}
I now want to take this json, place it into
resources/json/myendpoint.json
and read it from the file instead of having large json snippets in my kotlin code.
As an end result I'd love to be able to do this but I'm a bit in over my head in terms of grabbing a resource and converting it to a string. There seems to be like 1000 different ways to do this via SO and from what I would expect... maybe there's an easy way to do this with okhttp/mockwebserver/okio that I'm missing?
path == "/api/myendpoint" -> {
return MockResponse()
.setResponseCode(200)
.setBody(javaClass.classLoader.getResourceAsStream("json/myendpoint.json").toString())
}