0.0.2 • Published 6 years ago

callocall v0.0.2

Weekly downloads
4
License
ISC
Repository
github
Last release
6 years ago

CalloCall Callo Frontend API Wrapper

What is This?

This is the front-end API wrapper for Callo.

Its goal is to make it as easy to use as Meteor's Method.

Simple Documentation

Create a Session

let sess = CalloCall.session('http://localhost:8000/');

Add a Props Jar

sess.jar = { alwaysSent: 'somedata' }; // these props are sent every call, unless explicitly overwritten. Feels like cookie in a way

Initiate an API Call

(async () => {
    let data = await sess.dial('login', { username: 'kevin', password: '123456' });
    // data could also be access through sess.data
    // You can also optionally add some fetch settings
    // CalloCall under the hood uses fetch
    /*
    let data = await sess.dial('login', {
    	username: 'kevin',
    	password: '123456'
    }, {
        credentials: 'same-origin',
    });
    */
})();

Check Action and Reply

(async () => {
	try {
		await sess.dial('login', { username: 'kevin', password: '123456' });
        switch (sess.action) {
            case 'INVALID_PASSWORD':
                sess.reply({ password: 'valid_password' });
                break;
            case 'INVALID_USERNAME':
                sess.reply({ username: 'real username', password: '123456' });
                break;
            default: // sess.action === null means done/error
                if (sess.error) {
                    console.log(sess.error);
                }
                console.log('done!', sess.data);
        }
    } catch (err) {
		console.log(err);
	}
})();
0.0.2

6 years ago

0.0.1

6 years ago