Generating Fully-Qualified URLs for REST Resources
In most REST-based services, representations are hypermedia documents that contain not just data, but links to other resources.
Use the GetUrl method contained in the %IntBroker class to generate fully-qualified URLs for REST service operation resources. You can use the URLs with defined HTML definitions to dynamically add REST-based web service URL links.
Note:
A provider or a consumer REST based service operation representation can be used to generate the fully-qualified link(s).
The syntax of the GetUrl method is:
string &str = %IntBroker.GetURL( string <Service Operation>, integer
<Resource Index of Service Operation>, document <Document object
defined for document Template> , <optional> bool <secure/ unsecure
REST tgt location>, <optional> bool <add encoding for unsafe characters >The following example shows within an implementation (OnRequest event) of a REST-based provider service, HTML is generated using links defined from other REST-based service operations.
method OnRequest
Local Document &Doc_Tmpl, &DOC;
Local Compound &COM_Tmpl, &COM;
Local Message &response;
Local string &STR, &STR1, &STR2, &STR3, &STR4, &strHTML;
Local boolean &bRet;
&response = CreateMessage(Operation.WEATHERSTATION_GET, %IntBroker_Response);
/* read URI Document to get parms out from the request*/
&Doc_Tmpl = &MSG.GetURIDocument();
&COM_Tmpl = &Doc_Tmpl.DocumentElement;
/* Instantiate a Document object based on the REST based Service */
/* Operations Document Template for which to create a link. */
&DOC = CreateDocument("Weather", "WeatherTemplate", "v1");
&COM = &DOC.DocumentElement;
/* based off the data from the request populate the Document object */
If &COM_Tmpl.GetPropertyByName("state").Value = "Washington" Then
&COM.GetPropertyByName("state").Value = "Washington";
/* call new method to create fully qualified URL(s) */
&COM.GetPropertyByName("city").Value = "WhiteSalmon";
&STR = %IntBroker.GetURL("WEATHERSTATION_GET", 2, &DOC);
&COM.GetPropertyByName("city").Value = "Troutlake";
&STR1 = %IntBroker.GetURL("WEATHERSTATION_GET", 2, &DOC);
&COM.GetPropertyByName("city").Value = "Yakima";
&STR2 = %IntBroker.GetURL("WEATHERSTATION_GET", 2, &DOC);
&COM.GetPropertyByName("city").Value = "Lyle";
&STR3 = %IntBroker.GetURL("WEATHERSTATION_GET", 2, &DOC);
/* use these URLs as bind variables for the HTML definition */
&strHTML = GetHTMLText(HTML.WEATHER_CITIES, &STR, &STR1, &STR2, &STR3);
/* set the data in the response message */
&bRet = &response.SetContentString(&strHTML);
End-If;
Return &response;
end-method;