prooph / link

Automated Workflow Processing
BSD 3-Clause "New" or "Revised" License
13 stars 1 forks source link

Provide http request utils #48

Open codeliner opened 9 years ago

codeliner commented 9 years ago

Depends on #47

Simplify API requests by providing a command and a query module to perform requests.

Here is a prototype of a command module:

(function (root, factory) {
    if (typeof define === 'function' && define.amd) {
        define(['http', 'apiDefinition'], factory);
    } else {
        root.command = factory(root.http, root.apiDefinition);
    }
}(this, function (http, apiDefinition /* @TODO: add promise dependency */) {

    function command (name) {
        var self = this;

        self.name = name;

        self.setPayload = function (payload) {
            self.payload = payload;
        }

        self.send = function () {
            //@TODO return promise
            http.post(apiDefinition.getCommandUrl(self.name), self.payload)
        }
    }

    return command;
}));