You are here: Web Services > Consuming Web Services > Using XPRIM_UriBuilder to Build Your URL

Using XPRIM_UriBuilder to Build Your URL

You can easily build your request URL using the XPRIM_UriBuilder class.

The benefit of using XPRIM_UriBuilder (as opposed to manually constructing your URL by concatenating the parts) becomes apparent when you have variable values to be included in your query string or a path component.

Field names/values in a query string must be URL-encoded, and XPRIM_UriBuilder does that for you behind the scene.

It's strongly recommended to use XPRIM_UriBuilder to build your URL, even when your URL is simple. Neglecting to URL-encode a value that is supposed to be URL-encoded may lead to corrupted information getting transmitted to the server.

As an example, let's have a look at how we can easily construct a URL to use the Google Maps Geocoding service (to convert an address to a geographical coordinate).

The format of the URL is as follows:

https://maps.googleapis.com/maps/api/geocode/json?address={address}&key={key}

Below is the code example:

Define_Com Class(#XPRIM_UriBuilder) Name(#Url)

#Url.SetScheme( 'https' )

#Url.SetHost( 'maps.googleapis.com' )

#Url.SetPath( '/maps/api/geocode/json' )

#Url.AddQueryString( 'address' #Address )

#Url.AddQueryString( 'key' #ApiKey )

Next: Adding Request Headers