httpbuilder
httpbuilder copied to clipboard
URL placeholders with slash impossible / Add support for path variables
The current documented way of using path variables is as follows:
resp = twitter.delete( path: "destroy/${postID}.json" )
But what if the postID
wasn't numeric and contained a forward slash? The URL would end up being something like destroy/mypost/4711.json
whereas what we expected was destroy/mypost%2F4711.json
. If we try to encode the parameter manually while concatenating the string, we end up with a double-escaped slash: destroy/mypost%252F4711.json
. As of now, there doesn't seem to be any way to transmit a single encoded slash in the URL.
A good solution would be introducing path variables, like in Spring MVC. That could look something like this:
resp = twitter.delete( path: 'destroy/{postID}.json', pathVariables: [postID: 'mypost/4711'] )
This could be escaped and used exactly as the query map in URIBuilder.