Content routing

Home / Content routing
Apart from using a DimML application to collect data, a DimML application can also be  used to provide content dynamically. To achieve this a DimML application can at run time process process data and dynamically route the user agent to different content. This results in extensive personalisation options. Even with the same URL that is used, DimML can route the request to different content. That means that a web page can have 1 URL implemented as content on a page, but the content can be different based on the user preference, current weather or any data source imaginable.

The first way to achieve this, is to use the HTML plugin. This plugin allows you to define HTML code which will be executed the moment the URL is opened. The match rule of the concept can be used to define several different personalised HTML pages in 1 DimML application

To call the DimML application (without specific headers), the following URL has to be opened:

http://dynamic.dimml.io/content/[hash]/

The hash value of the DimML application can be found by opening the O2MC studio, right clicking on Properties and clicking Publishing API. Several properties and examples are available, the second property Hash is the one that is used for content routing.

The code for a HTML page is:

@groovy
concept Html {
	match '*.html'

	plugin html `
		<p>What a nice line of text</p>
		<p>And another one!</p>
	`
}

Note that opening looking at the match rule in this example, the URL http://dynamic.dimml.io/content/[hash]/page.html will show the HTML code, but http://dynamic.dimml.io/content/[hash]/page.htm will not (since the match is on “.html”).

Apart from HTML code, it is also possible to route the request to specific content. For this the content plugin is used, which requires a field as argument containing the URL to route to. The following code routes the DimML URL automatically to a picture URL:

@groovy 
concept Img { 
	match '*.png' 

	flow  
	=> code[img = `"https://unsplash.it/200/300"`@groovy] 
	=> out 

	plugin content `img` 
}

A more extensive example, which routes the URL to a different picture, based on the current weather can be found here.

Additional assigment

  1. Change the HTML example to provide a page which contains the current time of the day
  2. Change the Content routing example to route to a different picture based on the current time of the day