<commit_before>/*
    # api.js

    An exemplary headless controller module to handle client site API actions.

    **Usage:**

    - ** /api**: will run the **default** action as no action is specified.
    - ** /api/someGetAction**: will run **someGetAction**.
 */
define(['restController', 'module', 'conf'], function(RestController, module, conf) {
    return RestController.override({
        moduleId: module.id,
        'get-actions': {
            // a default action if no action is specified
            default: function (request, response) {
                // as a sample response return this API and action info
                response.end(JSON.stringify({
                    controller: 'api',
                    method: 'GET',
                    action: 'default',
                    status: 'success'
                }));
            },
            // some other API called from a client
            someGetAction: function (request, response) {
                // for example, first make sure this request is generated from our own site.
                if (request.headers && request.headers['host'] && request.headers['host'].indexOf(conf.app.domains.root) == 0) {
                    // as a sample response return this API and action info
                    response.end(JSON.stringify({
                        controller: 'api',
                        method: 'GET',
                        action: 'someGetAction',
                        status: 'success'
                    }));
                }
                else{
                    // otherwise, it's prohibited
                    response.statusCode = 403;
                    response.end();
                }
            }
            // other GET actions can be added here
        }
        // other actions can be added here
    });
});<commit_msg>Added docco compatible documentation comments.<commit_after>//
// An exemplary headless controller to handle client site API actions. Users can either extend this module by adding more functionality to it, or create their own based on this code.
//
// **Usage**
//
// 1. Must override properties  (at least `moduleId`) of a **RestController** (*/pulsr/restController.js*).
// 2. Optionally can provide `GET`, `POST`, `DELETE`, etc. properties like `get-actions` shown above.
//     - When a `GET` request for */api/someGetAction* is arrived, the **RestController** will check if `get-actions` property exists. If it exists, it checks whether or not `someGetAction` is defined in `get-actions`. If it does, it calls the function assigned to that action to handle the request.
//     - In case no action is requested, eg. */api* with no action specified, the **default** action will be executed. If no default action is provided, 405 Method Not Allowed response is returned.
//
// **Requesting**
//
// - **/api**: will run the **default** action as no action is specified.
// - **/api/someGetAction**: will run **someGetAction**.
//
define(['restController', 'module', 'conf'], function(RestController, module, conf) {
    return RestController.override({
        moduleId: module.id,
        // This controller will respond to `GET` requests for those actions only which are indicated in this hash.
        'get-actions': {
            // A default action if no action is specified.
            default: function (request, response) {
                // As a sample response return this API and action info.
                response.end(JSON.stringify({
                    controller: 'api',
                    method: 'GET',
                    action: 'default',
                    status: 'success'
                }));
            },
            // Some other API called from a client.
            someGetAction: function (request, response) {
                // For example, first make sure this request is generated from our own site.
                if (request.headers && request.headers['host'] && request.headers['host'].indexOf(conf.app.domains.root) == 0) {
                    // As a sample response return this API and action info.
                    response.end(JSON.stringify({
                        controller: 'api',
                        method: 'GET',
                        action: 'someGetAction',
                        status: 'success'
                    }));
                }
                else{
                    // Otherwise, it's prohibited
                    response.statusCode = 403;
                    response.end();
                }
            }
            // Other GET actions can be added here.
        }
        // Other HTTP actions can be added here.
    });
});
{'fraction_non_alphanumeric': 0.10620985010706638, 'fraction_numerical': 0.00278372591006424, 'mean_word_length': 1.6256323777403034, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6392680', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1043, 'n_words': 418}