servler
Authenticated service API with generic actions and persistent content types
Last updated 6 months ago by eliot .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install servler 
SYNC missed versions from official npm registry.

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

Current Tags

  • 1.0.3                                ...           latest (6 months ago)

5 Versions

  • 1.0.3                                ...           6 months ago
  • 1.0.2                                ...           6 months ago
  • 1.0.1                                ...           6 months ago
  • 1.0.0                                ...           6 months ago
  • 0.1.0                                ...           6 months ago

Copyright 2014 - 2016 © taobao.org |