0.2.3 • Published 5 years ago

djax-client v0.2.3

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

djax-client

A straightforward services client powered by djax.

Example

var Client = require('djax-client');

// Creating the client
var client = new Client({

  // Client's settings
  settings: {
    baseUrl: 'http://localhost:8000',
    engine: $.ajax,
    scope: null,
    solver: /\:([^/:\?]+)/g
  },

  // Default call options
  defaults: {
    type: 'GET',
    dataType: 'json',
    params: {
      param: 'item',
      dynamicParam: function() {
        return 'user';
      }
    }
  },

  // Defining our services
  services: {
    getItem: '/item/:id',
    getUser: {
      url: '/:param/:id',
      success: function(data) {
        console.log('Got user!', data);
      }
    },
    createItem: {
      url: '/:dynamicParam',
      type: 'POST',
      headers: {
        Authorization: function() {
          return model.getAuth();
        },
        'X-Option': 'hello!'
      }
    }
  }
});

// Using the client
client.request({url: '/items'}, function(err, data) {
  console.log(data);
});

client.request('getItem', {params: {id: 34}}, callback);
client.getItem({params: {id: 34}}, callback);

// etc.

Development

# Building
npm run build

# Testing
npm test

# Linting
npm run lint

# Working (localhost:7337/static/unit.html)
npm run work

License

MIT

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.1

9 years ago

0.1.0

9 years ago