Constructing and modifying complex URLs
At the heart of any HTTP request, there is a Universal Resource Locator (URL) or a more generic Universal Resource Identifier (URI) which identifies the target of the operation we need to perform.
We have seen in the previous recipes (for example, the Downloading content from the Internet recipe) that it's very hard to avoid dealing with URLs when interacting with the HTTP protocol. In this recipe, we are going to present a more structured approach to constructing and modifying complex URLs with the help of an additional Groovy library.
How to do it...
If you have worked with Java's URL
class before, you know that the only way to construct instances of that class is to provide a full URL to the constructor, which will return an immutable (non-changeable) object.
Groovy's core does not add any special support for URL manipulation apart from what Java already offers, but there is an officially supported HttpBuilder
module that is hosted on Groovy's website...