Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    rest-io-clientpublic

    rest-io-client

    Client es6 class for Promise based websocket requests to server implementing rest-io-router

    Installation  

    With node [installed]:

     
    $ npm install rest-io-client --save

    Usage

        import RestSocket from 'rest-io-client'
     
        /*
            class RestSocket
     
            params:
                url: required
                options: optional socket.io options object
        */
        var socket = new RestSocket(url)
     
        socket.get("/users").then(data => {
            ...
        })

    API

        get(url[, params, query]).then(data => {..}).catch(err => {...})
        post(url[, params, query]).then(data => {..}).catch(err => {...})
        put(url[, params, query]).then(data => {..}).catch(err => {...})
        delete(url[, params, query]).then(data => {..}).catch(err => {...})
     
        *Note*
        params = any valid js object
        query = any valid js object

    url may also contain query strings as below

        get("/users?id=foo").then(.....

    Emitting/Receiving via socket.io

        import RestSocket from 'rest-io-client'
     
        var socket = new RestSocket(url)
     
        socket.on('foo', msg => {...})
        socket.emit('bar', data)
     
        *Note Reserved for Promise based API*
        socket.on('rest',...
        socket.emit('rest',...

    Keywords

    none

    install

    npm i rest-io-client

    Downloadsweekly downloads

    6

    version

    0.1.2

    license

    ISC

    repository

    githubgithub

    last publish

    collaborators

    • avatar