Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/eliot-akira/servler

Authenticated service API with generic actions and persistent content types
https://github.com/eliot-akira/servler

Last synced: about 1 month ago
JSON representation

Authenticated service API with generic actions and persistent content types

Awesome Lists containing this project

README

        

# Servler

Authenticated service API with generic actions and persistent content types

## Serve

```js
import servler from 'servler'

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

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

## Request

All actions are called via `POST` method.

```json
{
"type": "page",
"action": "insert",
"data": {
"title": "Hello world",
"content": "Hi!"
}
}
```

## WebSocket

```js
const webSocketServer = async (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

```sh
yarn
```

Develop: Watch files; Recompile and type check on changes

```sh
yarn dev
```

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

```sh
yarn test
```

Build

```sh
yarn build
```

Publish to NPM

```sh
npm run release
```