Related off of the above question. I'm using mockw...
# squarelibraries
c
Related off of the above question. I'm using mockwebserver and creating my own dispatcher. Which originally was a really simple when statement, but now I'm dealing with api calls that have url params and I feel like I'm missing something basic in order to get something like "wildcards" working correctly.
Copy code
when (request.path) {
    "/api/one/two" ->
        return "blah"
    "/api/three/four?arg=myArg" ->
        return "boop"
I want the second case to basically catch all 
api/three/four*
 instead of hard coding the arg. Or maybe there's another way I should go about this. e.g. Only get the path without the args, and then if I need the args I can drill down and get them from the request if need be? Thoughts?
m
Use a Regex?
Copy code
when {
  requestPath == "/api/one/two" -> "blah"
  Regex("/api/three/four.*").matchEntire(requestPath) -> "boop"
}
I didn't find anything into OkHttp to parse a recorded path into path + queryParams + fragment but I guess you could also prepend "http://example.com/" and use
toHttpUrl()
j
Or use Android's Uri or the JDK's URI to do it
c
Ooh. Yeah regex sounds doable. And okay I will look up URI and see what it offers. Cheers
Thanks for the tip on the JDKs URI class. This did the trick. Especially helpful since my dispatcher is in a java only module. Cheers
Copy code
val asdf = URI.create(request.path!!)
            when (asdf.path) {
...
Oooh. Stumbled upon https://square.github.io/okhttp/4.x/okhttp/okhttp3/-http-url/ This might be what I want since it simplifies getting query params.