We can turn a URL string value into an object with fields that contain information about the URL using the parseURI
function. This function is part of the code dw::core::URL
module. The returned object is of type URI
and has fields like host
, path
, query
, scheme
and more.
In the following example we use the parseURI
function on the URL https://blog.mrhaki.com/search?q=DataWeave
and in the output we can see the different fields:
Source
%dw 2.0 import parseURI from dw::core::URL var blogURI = parseURI("https://blog.mrhaki.com/search?q=DataWeave") output application/json --- // URI object has fields with information about the parsed URL. blogURI
Output
{ "isValid": true, "raw": "https://blog.mrhaki.com/search?q=DataWeave", "host": "blog.mrhaki.com", "authority": "blog.mrhaki.com", "path": "/search", "query": "q=DataWeave", "scheme": "https", "isAbsolute": true, "isOpaque": false }
Written with DavaWeave 2.4.