servess
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

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')
}()

Package Sidebar

Install

npm i servess

Weekly Downloads

1

Version

1.1.0

License

MIT

Unpacked Size

99.4 kB

Total Files

26

Last publish

Collaborators

  • poroshadows