Embedthis Appweb 3.4.0
Home > Programming Guide > Creating Appweb Modules

See Also

Creating Appweb Modules

Appweb supports extension modules that can augment the capability of Appweb by adding new features, handlers, protocols or any arbitrary code.

Appweb is itself comprised of thirteen different modules. The core appweb HTTP server cannot serve any pages or documents by itself. It relies on request handlers packaged as modules to actually serve HTTP requests. Other Appweb modules provide SSL, authorization and file upload.

This document describes the Appweb Module Interface and how to create Appweb modules. The Appweb Module interface supports both dynamicaly loaded and statically linked modules from a single C code base.

Overview

To create an Appweb module, you must create an initialization function that is called when Appweb loads your module. This must be named according to the form:

mprNameModuleInit(MaHttp *http)

where Name is the name of your module. The first letter must be upper case. This function will be called immediately after loading the module code.

The initialization function must call the mprCreateModule API and supply a unique name, module version string and optional module data and start/stop functions. This call returns a module instance that is registered with Appweb.

MprModule *maSimpleModuleInit(MaHttp *http)
{
    MprModule   *module;
    module = mprCreateModule(http, "testModule", "1.0.0", NULL, NULL, NULL);
    if (module == 0) {
        return 0;
    }
    /* Put custom initialization here */
    return module;
}

Initialization functions are passed the Http service object as a parameter and must return the module object for the module. You can put any custom code in the initialization function. If you supply start or stop functions as parameters to the mprCreateModule API, these will be invoked when Appweb starts.

Modules can be dynamically loaded in response to the LoadModule Appweb configuration directive. You can also load modules via the maLoadModule C API.

To package your module, you must create a DLL / shared library containing your module and on Windows, you must export the initialization function. If you want to statically link your module, you need to ensure the main program explicitly calls your initialization function during its initialization.

© Embedthis Software LLC, 2003-2012. All rights reserved. Embedthis, Ejscript and Appweb are trademarks of Embedthis Software LLC.