1.1.0 • Published 3 years ago
servess v1.1.0
Servess
This is yet another routing library that takes some insperation from express and ktor. The module itself is a router with extension hooks. All routes are async.
A small example
import createApp from 'servess'
void async function main() {
const app = createApp()
app.get('/', () => 'Hello, world!')
await app.listen(3000)
console.log('> Listening: http://localhost:3000')
}()
Content negotiation
app.get('/', ctx => ctx.accepting({
html: () => {
ctx.setHeader('Content-Type', 'html')
return `<p>Hello, world!</p>`
},
json: () => ctx.json({ hello: 'world' }),
else: () => 'Hello, world'
}))
Extensions
import createApp from 'servess'
// Type 1 static import
import Templating from 'servess-tmpl'
void async function main() {
const app = createApp()
app.install(Templating)
// Type 2 dynamic import
app.install(import('servess-ws'))
await app.listen(3000)
console.log('> Listening: http://localhost:3000')
}()