This is a short Sioux tutorial. It shows how to write and build simple Nemerle web application.

First of all open your favorite text editor and start coding:

using Sioux;
using Nemerle.Xml;
using System.Xml;

public class MyFirstApp : Application
{
    override protected DoGet() : void
    {
        def doc = XmlDocument();
        doc.Load("my_first_app.xml");
        this.FormTemplate = Some (XmlTemplate(doc));
    }
}
    

Save it as "my_first_app.n" and type:

ncc -r:Sioux -tdll -o:MyFirstApp.dll my_first_app.n
cp MyFirstApp.dll webapps/

in terminal.

Now, we'll explain our code:

using Sioux;
    

Let compiler know we're using Sioux namespace. It contains basic classes such as Application, Request etc.

using Nemerle.Xml;
using System.Xml;
    

We are operating on Xml documents in Sioux. System.Xml namespace contains XmlDocument class and Nemerle.Xml namespace contains XmlTemplate class.

public class MyFirstApp : Application
{
   ...
}
    

Every Sioux application is a subclass of Sioux.Application class.

override protected DoGet() : void
{
   ...
}
    

Sioux application handles GET and POST requests. If we want to handle GET request we have to override DoGet() method.

def doc = XmlDocument();
doc.Load("/my_first_app.xml");
this.FormTemplate = Some (XmlTemplate(doc));
    

If we want to display my_first_app.xml we have to load it, create XmlTemplate object and tell Sioux that it is our FormTemplate. FormTemplate is a field in Sioux.Application object, which contains XmlTemplate object that is displayed when our app is handling request.

All we have to do now is to write my_first_app.xml. Here's the code:

<html>
<head>
<title>My first Sioux application</title>
</head>
<body>
<h1>
This is my first Sioux application
</h1>
</body>
</html>
    

Assuming that Sioux is running, open your browser and enter:

http://localhost/webapp/MyFirstApp/

Let's assume that we have two XML files: file1.xml and file2.xml and we want to use them both in our application.

<!-- FILE1.XML -->
<html>
<head>
<title>First file</title>
</head>
<body>
<h1>
This is file1.xml
</h1>
</body>
</html>
    
<!-- FILE2.XML -->
<html>
<head>
<title>Second file</title>
</head>
<body>
<h1>
This is file2.xml 
</h1>
</body>
</html>
    

Let's write code:

using Sioux;
using Nemerle.Xml;
using System.Xml;

public class SecondApp : Application
{
    override protected DoGet() : void
    {
        def doc = XmlDocument();
	match(PageName)
	{
	    | "/file2.xml" => doc.Load("file2.xml");
	    | _ => doc.Load("file1.xml");
	}
        
        this.FormTemplate = Some (XmlTemplate(doc));
    }
}
    


Save it as "second_app.n" and type:

ncc -r:Sioux -tdll -o:SecondApp.dll second_app.n
cp SecondApp.dll webapps/

in terminal. To run type:

http://localhost/webapp/MyFirstApp/

There is one part of code different than in first example:

match(PageName)
{
    | "/file2.xml" => doc.Load("file2.xml");
    | _ => doc.Load("file1.xml");
}
    


PageName field in instance of Application class is a part of request url. It is a substring of request url, beginning right after application name.
If we type

http://localhost/webapp/SecondApp/file2.xml

PageName field will be "/file2.xml", when we type

http://localhost/webapp/SecondApp/

PageName will be "/".
Finally, if we type

http://localhost/webapp/SecondApp/file2.xml

our application will display file2.xml, if we type

http://localhost/webapp/SecondApp/file1.xml

our application will display file1.xml.