1.0.3 • Published 4 years ago

servler v1.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

Servler

Authenticated service API with generic actions and persistent content types

Serve

import servler from 'servler'

servler({
  contentTypes: {
    post: {
      defaultItems: [],
      actions: {

      }
    }
  },
  actions: {
    ping(data, context) {
      return {
        message: 'pong',
        data
      }
    }
  }
}).catch(console.error)

Request

All actions are called via POST method.

{
  "type": "post",
  "action": "insert",
  "data": {
    "title": "Hello world",
    "content": "Hi!"
  }
}

WebSocket

const webSocketServer = (io, context) => {

  io.on('connection', socket => {

    console.log('a user connected')

    socket.on('disconnect', () => {
      console.log('user disconnected')
    })

    socket.on('chat message', msg => {
      console.log(`message: ${msg}`)
      io.emit('chat message', msg)
    })
  })
}

servler({ ...config, webSocketServer })

Develop this library

Install dependencies

yarn

Develop: Watch files; Recompile and type check on changes

yarn dev

While the above is running, run tests (and watch/retest) in another terminal window:

yarn test

Build

yarn build

Publish to NPM

npm run release