In the first part of this post we discussed how the SQL Anywhere HTTP Server routes web requests. In brief, when a web request enters the web server, the web server will route the request to the service that most specifically identifies it. This post explains with how you can use the remaining part of the URL that does not match. In short, if we have defined a service,
CREATE SERVICE "alice/files" AUTHORIZATION OFF USER DBA TYPE ‘RAW’ URL OFF AS CALL get_file();

and we try to access the document http://www.host.com/alice/files/business/overview, how does our service use the remainder of the URL (the 'business/overview' part in this case)?

The answer lies in the URL parameter of the service definition. The URL parameter can take three values, and the default value is URL OFF. With URL OFF, the service will not be used unless the URL identically matches the service name. So this case, not only can we not use the remaining part of the URL, but the service simply won’t work.

To allow access to the remaining part of the URL, we have two options. The first is to set URL ON. When URL is ON, a variable called :url is automatically created that contains the remaining part of the URL. Let’s say we altered the service to be:

ALTER SERVICE "alice/files" AUTHORIZATION OFF USER DBA TYPE ‘RAW’ URL ON AS CALL get_file(:url);
Now we have access to the :url variable that contains 'business/overview‘, and we can pass that to the stored procedure that handles this service. The drawback to URL ON is that even if the remaining URL contains many elements, it will still only be captured as a single string. This is where the URL ELEMENTS is useful.

URL ELEMENTS works differently. Instead of creating a single variable called :url that contains the whole string, it creates many variables each representing a part of the URL. These variables are called :url1, :url2, ... , :url10. It will create as many variables as there are parts to the URL up to a maximum of 10.

Suppose your application uses RESTful services and the URLs to browse your product catalog all are of the form:

/[DEPARMENT]/[PRODUCT]/[SIZE]

A sample URL for this application might be:

www.host.com/Catalog/Mens/Polo_Shirt/Large

If you defined a service called Catalog and set URL ON, the :url variable would contain the entire string 'Mens/Polo_Shirt/Large‘. By using URL ELEMENTS, you instead end up with three strings:
:url1 = 'Mens':url2 = 'Polo_Shirt':url3 = 'Large'
These string can then be passed into the stored procedure that handles the service as shown below.
CREATE SERVICE "Catalog" AUTHORIZATION OFF USER DBA TYPE ‘RAW’ URL ELEMENTS AS CALL get_price(:url1, :url2, :url3)

New NetWeaver Information at SAP.com

Very Helpfull

User Rating: Be the first one !