Wexus2 0.20
Wexus Programmer's Tutorial

This tutorial will quickly outline how to make a Wexus app. This tutorial was made while building the wexus::UptimeApp application, so you can open the source files for that and follow along.

Creating your Application object

An application object represents the persistent state your application needs between controller calls. Many applications don't need to put any additional logic in their application objects, but they provide a handy service when they are needed.

Create your application class by deriving from wexus::Application You don't need to to implement any of the methods, but you should probably provide a constructor:

  class wexus::UptimeApp : public wexus::Application
  {
    public:
      /// default constructor
      UptimeApp(void);
  };

You must also register your application. You do this in your .cpp file by instantiating a small static class, providing your class type and a unique string describing the string. You can embed your organizations domain name (in reverse order) to help make your name unique.

For example:

  static wexus::RegisterApp<wexus::UptimeApp> r1("ca.demko.uptime");

Note that the instance name of this object ("r1" in this case) is not used anywhere, so we typically give them short, arbitrary names.

Creating a Controller object

Now you will need one or more controller objects. Typically, you register one or more methods of your controller objects as "actions" for URLs. When a web user accesses one of those URLs, the appropriate controller object is instantiated and the desired method is then called.

Controller objects are not persistent - they are instantiated and destroyed per call.

Here is an example of a declaration of a Controller and one method:

  class wexus::UptimeController : public wexus::Controller
  {
    public:
      void index(void);
  };

And the implementation of the method:

  void UptimeController::index(void)
  {
    htmlOutput() << "Hello, world";
  }

Finally, we need to register the controller, and bind it to the application type. We also need to register each action method. Again, the instance names of these objects are arbitrary:

We can now compile and run the application. Simply:

  • Make an app.ini that will tell the wexusserver application what to load (the contents of this app.ini are below).
  • Run "wexusserver dir", where dir is the directory containing the app.ini. It could be "." (the current directory).
  • Load http://localhost:8080/home/index in your web browser.
  • Alternatively, load http://localhost:8080/home This works because "index" is the default action of any controller.
  • Alternatively, load http://localhost:8080/ This works because "home" is the default controller of an application

Here is the app.ini

  [myappinstance]
  app = ca.demko.uptime

Rendering HTML

(yet to be written)

 All Classes Namespaces Functions Variables Enumerations Enumerator