FOSSASIA March 2015
@soareschen
GET /blog/first-post
Stream
Handler
Builder
Filter
Middleware
Component
import { simpleHandlerBuilder } from 'quiver-core/component'
export let getBlogPostHandler = simpleHandlerBuilder(
(config) => {
let { db } = config
return async function(args) {
let { postId } = args
let post = await db.query(...)
return post
}
})
.inputType('void')
.outputType('text')
let blogPostHandler = simpleHandlerBuilder(...)
.middleware(databaseMiddleware)
.middleware(cacheFilter)
.middleware(permissionFilter)
let databaseMiddleware = configMiddleware(...)
let cacheFilter = streamFilter(...)
let userInfoHandler = simpleHandlerBuilder(...)
.middleware(databaseMiddleware)
.middeware(cacheFilter)
let permissionFilter = argsFilter(...)
.inputHandler(userInfoHandler)
let blogPostHandler = simpleHandlerBuilder(...)
.middleware(databaseMiddleware)
.middleware(cacheFilter)
.middleware(permissionFilter)
import { router } from 'quiver-core/component'
import { startServer } from 'quiver-core/http'
import {
userInfoHandler, blogPostHandler, httpFilter
} from './my-components'
let main = router()
.paramRoute('/user/:userId', userInfoHandler)
.paramRoute('/blog/:postId', blogPostHandler)
.middleware(httpFilter)
startServer(main, config)
.then(server => {
console.log('Server running...')
})
.catch(err => {
console.log('error starting server:', err.stack)
})
Feedback?
tweet to @soareschen