Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/eliot-akira/servler
- Owner: eliot-akira
- Created: 2020-02-02T04:42:31.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-02-03T13:27:39.000Z (almost 5 years ago)
- Last Synced: 2024-09-10T18:33:35.963Z (2 months ago)
- Language: TypeScript
- Size: 20.5 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
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
```