sttp
sttp copied to clipboard
Uri with original masking
In brief: I would like to have access to the preinterpolated version of uri.
I want to get metrics for my SttpBackends grouped by paths. Requests like GET /users/123 and GET /users/1234 should be grouped together. I had a look at PrometheusBackend where I would have to keep the masks of paths /users/{} somewhere. I also would have to write interpreters of the masks to match a given request to the mask and handle the cases when they do not match.
I thought, it would be nice if I could extract the original mask of the uri from the request on its creation.
If you have a look at the Uri documentation you will notice, the mask is already there.
I create all the requests in such a way:
val baseUrl = "http://my.address.com/api" // actually goes from config
val userId = 123
val uri = uri"$baseUrl/users/$userId"
basicRequest.get(uri)
I would be pretty happy if I could retrieve the original uri string without substitutions
uri.originalMask // "$baseUrl/users/$userId"
And the masking for metrics will be trivial to write.
What do you think about such a feature?
I understand the rationale but I think it would be quite tricky to implement. Definitely not trivial :)