def uri = new UriBuilder('http://someurl.com/api')
I want to append /$contacId/PhoneNumber
to the above uri
.
How Do I handle this case
def uri = new UriBuilder('http://someurl.com/api')
I want to append /$contacId/PhoneNumber
to the above uri
.
How Do I handle this case
use path method
def uri = new URIBuilder('http://someurl.com/api');
uri.path("/$contacId/PhoneNumber");
One-Liner using UriBuilder:
import javax.ws.rs.core.UriBuilder
def contactId = 42
def uri = UriBuilder.fromUri("http://someurl.com/api").path("$contactId/PhoneNumber")
println uri
Output:
http://someurl.com/api/42/PhoneNumber
Test:
Copy-paste the code into https://groovy-playground.appspot.com/
https://docs.oracle.com/javaee/7/api/javax/ws/rs/core/UriBuilder.html
def uri = new URIBuilder('http://someurl.com/api')
String appendPath = "/contact/$contactId/PhoneNumber"
uri.path += appendPath;