Motivation
Websockets are way faster than http. This package seeks to provide a replacement for http when creating RESTful APIs.
To do
- Limit calls to WATCH handler so that it's only called when the matches of the query is changed. Now it is triggered for all changes within a resource.
- Move
CHANGE
-events away from strategy
Usage
Client
const io = const realtime = io // Meta data for all messages realtimeoptionstoken = 'some jwt token' // Create { return realtime} // Read { return realtime} { return realtime} { return realtime} { return realtime} // Watch/unwatch { const watchId = await realtime return { return realtime }} { const watchId = realtime return { return realtime }} // Update { return realtime} // Delete { return realtime}
Server
const server = httpconst io = const events = const resources = 'users' const databaseAdapter = async { // Return one instance of the resource matching the query // ‹Your implementation› } async { // Return an array of instances matching the query // ‹Your implementation› } async { // Update an instance of the query using updates = { id, ...updates } // ‹Your implementation› // Then notify socketio-rest that a change has occurred events } async { // Create an instance of the resource // ‹Your implementation› // Then notify socketio-rest that a change has occurred events } async { // Delete an instance of the resource // ‹Your implementation› // Then notify socketio-rest that a change has occurred events } // Initialize const realtime = io resources // Specify a strategy const strategy = db events realtime server
Testing
yarn test
npm test