Skip to content

Instantly share code, notes, and snippets.

View daffl's full-sized avatar

David Luecke daffl

View GitHub Profile
@daffl
daffl / app.js
Created November 12, 2018 01:16
A Koa middleware example
const Koa = require('koa');
const app = new Koa();
app.use(async (ctx, next) => {
// Store the start time
const start = Date.now();
// Pass to the next middleware and wait for everything to return
await next();
@daffl
daffl / service-events.md
Last active January 31, 2024 09:24
HTTP methods, service layer and real-time event mapping
HTTP method Service layer method Real-time event
GET /messages messages.find() -
GET /messages/1 messages.get(1) -
POST /messages messages.create(body) message created
PUT /messages/1 messages.update(1, body) message updated
PATCH /messages/1 messages.patch(1, body) message patched
DELETE /users/1 messages.remove(1, body) message removed
@daffl
daffl / http-methods.md
Last active November 27, 2018 07:46
HTTP method to service layer mapping
HTTP method Service layer method
GET /messages messages.find()
GET /messages/1 messages.get(1)
POST /messages messages.create(body)
PUT /messages/1 messages.update(1, body)
PATCH /messages/1 messages.patch(1, body)
DELETE /messages/1 messages.remove(1, body)
@daffl
daffl / service.js
Last active February 20, 2019 10:51
A RESTful service layer
class MessageService {
// Find a list of resources
find(params) {},
// Get a single resource by its id
get(id, params) {},
// Create a new resource
create(data, params) {},
// Replace an existing resource by its id with data
update(id, data, params) {},
// Merge new data into a resource
@daffl
daffl / app.js
Last active March 17, 2019 00:10
Basic service layer
class ChatApplication {
login (username, password) {},
logout (user) {},
joinChatRoom(roomId, user) {}
sendMessage(message, roomId, user) {}
sendPrivateMessage(message, receiverId, user) {}
dat://5757862252cb4131892a5a88c23570ba3e013cef0ecc95344172745b8af0b6ef
@daffl
daffl / app.js
Last active July 13, 2018 01:46
Node + MongoDB REST API in a tweet - `npm i @feathersjs/feathers @feathersjs/express mongodb feathers-mongodb`
const feathers = require('@feathersjs/feathers');
const express = require('@feathersjs/express');
const mongodb = require('mongodb');
const service = require('feathers-mongodb');
mongodb.MongoClient.connect(`mongodb://localhost:27017`).then(client => {
const app = express(feathers())
.configure(express.rest())
.use('/messages', express.json(), service({
Model: client.db('feathers').collection('messages')
@daffl
daffl / keybase.md
Created February 16, 2018 04:39
Keybase.io

Keybase proof

I hereby claim:

  • I am daffl on github.
  • I am daffl (https://keybase.io/daffl) on keybase.
  • I have a public key ASCYmmwbPb3c_9R7roOLDRTIkkg1pQe4g2CIiAJZ1Pd0Ywo

To claim this, I am signing this object:

@daffl
daffl / app.js
Last active January 6, 2022 16:43
Socket.io counter acknowledgement example
const app = require('express')();
const http = require('http').Server(app);
const io = require('socket.io')(http);
let counter = 0;
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
@daffl
daffl / app.js
Last active January 26, 2018 23:24
Feathers REST and websocket server with simple service
const path = require('path');
const feathers = require('@feathersjs/feathers');
const express = require('@feathersjs/express');
const socketio = require('@feathersjs/socketio');
// Heroku will set the PORT environment variable. Otherwise use 3030
const port = process.env.PORT || 3030;
// Creates an Express compatible Feathers application
const app = express(feathers());