Hi Günter,
sorry for the delay but here you go with a very small example that should show off what I told. You can copy the .xqm files into the webapp dir of a basex installation and and the .css files into the corresponding static folder. Then invoke the "entrypoint" RestXQ from within your browser with an url similar to

 http://localhost:8984/myapp/page1?user=Marco

As you can see the HTML page built from the entrypoint is composed of three parts. One that selects the styles to apply according to the user being anonymous or not. Then a common header markup is generated and finally a dynamic part that depends on the page element of the path.

It's really not anything special but nevertheless it should be useful in clarifying the approach.

Hoffe es gefaellt dir.
Herzliche Gruesse,
Marco.

On 10/04/2016 17:36, Günter Dunz-Wolff wrote:
Hi Marco,

it’s me again. Just to be more specific, I’m especially interested in your 
approach
- to pass parametric values into the „exploded“ modules
- to map requests to module invocations by exploiting REST path segments

It would be really helpful, to get some snippets of your code. Tanks a lot.

Ciao, Günter

Am 08.04.2016 um 10:13 schrieb Marco Lettere <m.lett...@gmail.com>:

Hi Günter,
we have worked on several web applications that include a frontend and we are 
very happy with using basex for serving both static (scripts, css, images) and 
dynamic (markup) content.
One pattern that we've used often and that we find very productive is to split 
markup content into different .xqm modules.
The modules are called through the xquery:invoke function in order to "explode" 
their output into the main page.
In our opinion this is a good approach because it is applicable recursively to 
sub-modules. Content of modules may be dynamic as well and parametric values 
are passed into the module through external variables.
Finally, it is possible to set up an automatic way of mapping requests to 
module invocations by exploiting REST path segments for example.
I hope I have been able to explain it well enough otherwise, just let me know 
and as soon as possible I'll provide an example code snippet that demonstrates 
the approach.

Ciao,
Marco.

On 07/04/2016 17:08, Günter Dunz-Wolff wrote:
Hi,

I'm planning to relaunch my website (kleist-digital.de) with OpenShift as 
BaseX-Server. After some difficulties and a lot of help from Christian and Andy 
the server is running now.

I took a look at RESTXQ and it seems quite interesting to build the whole 
frontend for my app with it. Some questions I have:

1. I'm working with a basic layout for all pages. This basic layout-file 
includes header, footer and changing content. What is the best approach with 
RESTXQ. How to build a modular concept with RESTXQ?

2. Is there any site-structure preferred?

3. Most of the site is dynamic. But I need also static files like images, css, 
javascript. Where to put them best (so that the Openshift-Server can handle 
them)?

Thanks for any advice and help.

Günter


declare variable $user as xs:string external;

if($user = 'anonymous') then

 <link rel="stylesheet" href="/static/style2.css"/>

else
 
 <link rel="stylesheet" href="/static/style1.css"/>
declare variable $user as xs:string external;

<p>
  Page content customized for {$user} here!
</p>
body{
  background-color: #aaffaa;
}
body{
  background-color: #ffaaaa;
}

This is an Example ...


module namespace sk = "urn:skeleton";

declare
  %rest:path('myapp/{$page}')
  %rest:GET
  %rest:query-param("user", "{$user}", "anonymous")
  %output:method("html")
function sk:impl_GET($page as xs:string, $user as xs:string) {
    <html>
      <head>
        {xquery:invoke("styles.xqm", map{ "user" : $user})}
      </head>
      <body>
        {xquery:invoke("commonheader.xqm", map{ "user" : $user})}
        {xquery:invoke($page || ".xqm", map{ "user" : $user})}
      </body>
    </html>
};

Reply via email to