Blog for web developers

Jquery API call object oriented way

In this another small article I am going to show you how you can write function in object oriented way.

var app = {
    createApiPath: function(apiController, apiAction) {
        var jsonUrl = jsonAPIUrl + 'api/' + apiController + '/' + apiAction + '/';
        return jsonUrl;

    apiCustomPost: function(apiController, apiAction, callParams, callback) {
            url: this.createApiPath(apiController, apiAction),
            type: "post",
            data: {
                callData: JSON.parse(JSON.stringify(callParams)),
                api_version: 1,
                deviceType: 'web'
            async: true,
            dataType: "json",
            success: callback,
            error: function(xhr, ajaxOptions, thrownError) {
                return false;


// now you can use this code like 
// app.apicustomPost(data1, data2, callParams, successCallback())

Santosh Shah

I am a JavaScript developer having enthusiasm on most frontend skills like JavaScript, HTML, CSS, SASS, node, gulp, angular etc. I love exploring new techniques and like to learn new technologies to keep my self up to date.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.