Webapp engine

Contents

Webapp engine

The Webapp engine is responsible for processing of requests on the endpoint :8080/webapp/<app-name>/*

Request pipeline

The webapp pipeline is executed as a subset of the common pipeline:

Webapp rendering pipeline

This section describes the full pipeline involved in processing a webapp http request.

Web app controller

Invokes the webapp controller of the contextual application

webapp.js

To turn your application into a webapp, simply place an http controller called /src/main/resources/webapp/webapp.js into your project.

When the application is deployed, the controller will be accessible from

``//<server>:<port>/webapp/<app-name>/`` (i.e. "localhost:8080/webapp/my.webapp/").

webapp.js now acts as a HTTP controller and may expose a function for each HTTP method that should be handled: i.e. GET, POST, etc.

Below is an example webapp controller.

var mustache = require('/lib/xp/mustache');

// Handles a GET request
exports.get = function (req) {

    var view = resolve('my-page.html');
    var params = {
        appId: app.name,
        title: 'Hello world'
    };

    return {
        body: mustache.render(view, params),
        contentType: 'text/html'
    };
};

// Handles a POST request
exports.post = function (req) {
    var name = request.params.name;

    return {
        body: {'Hello': name},
        contentType: 'application/json'
    };
};

// Handles all other method requests
exports.all = function (req) {
    if (req.method === 'DELETE') {
        handleDelete(req);

    } else if (req.method === 'PUT') {
        handlePut(req);
    }

    return {
        body: {'Hello': name, 'Method': req.method},
        contentType: 'application/json'
    };
};
To handle routing and filters in web apps, the implementer should use the router library.

Contents