Skip to content

Latest commit

 

History

History
47 lines (39 loc) · 1.17 KB

README.md

File metadata and controls

47 lines (39 loc) · 1.17 KB

sockrest-client

Realtime client that works to support protocol defined by sockrest

How to use

Client side implementation

import SockrestClient from 'sockrest-client'

let client = SockrestClient('ws://127.0.0.1:3000')

client.on('error', (err) => {
    console.error('connection error', err.message)
})

client.on('open', () => {
    client
        .get('/')
        // 2xx
        .then(res => {
            console.info('Just got response')
            console.info('Status Code:', res.statusCode)
            console.info('Body:', res.body)
        })
        // 4xx
        .catch(err => {
            console.error('Response was not get')
            console.error('Status Code:', err.statusCode);
        })

    client
        .post('/posts', { robot: 'I`m a client' })
        // 2xx
        .then(res => {
            console.info('Just got response')
            console.info('Status Code:', res.statusCode)
            console.info('Body:', res.body)
        })
        // 4xx
        .catch(err => {
            console.error('Response was not get')
            console.error('Status Code:', err.statusCode);
        })
})