0.6.0 • Published 8 years ago

soular v0.6.0

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

Soular :sunny: :earth_americas: :crescent_moon: Build Status Coverage Status

What is it?

  • Web server library
  • Based on promises and a single state atom to handle concurrency

Why use it?

  • Small, easy to use (<100 LOC)
  • 100% test coverage
  • Service Discovery
  • React Router integration

How does it work?

Promise.all(middleware).then(mapResultToHttpResponse).catch(ErrorHandler)

All middleware is run at the same time. Unused middleware should short circuit. Running middleware relies on the ctx.state variable to communicate with other middleware.

Basic Example

import soular from 'soular'

const getDBMiddleware = async ctx => {
  let db = await DBClient.getConnention()
  ctx.state.db = db
}

const handler = async ctx => {
  const db = await ctx.state.db
  const users = await db.getAllUsers()

  return {
    body: { users }
  }
}

soular('*')
  .use(getDBMiddleware)
  .use(handler)
  .listen()

Routing

import soular from 'soular'
import { GET } from 'soular/route'

const getDB = async ctx => {
  const db = await DBClient.getConnention()
  ctx.state.db = db
}

const getUsers = async ctx => {
  const db = await ctx.state = db
  const users = await db.getAllUsers()

  return {
    body: { users }
  }
}

const getAdmins = async ctx => {
  const db = await ctx.state.db
  const admins = await db.getAdmins()

  return {
    body: { admins }
  }
}

soular('*')
  .use(getDB)
  .use(GET('/users')(getUsers))
  .use(GET('/admins')(getAdmins))
  .listen()
0.6.0

8 years ago

0.4.0

8 years ago

0.3.8

8 years ago

0.3.7

8 years ago

0.3.6

8 years ago

0.3.5

8 years ago

0.3.4

8 years ago

0.3.3

8 years ago

0.3.2

8 years ago

0.3.1

8 years ago

0.3.0

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.0

8 years ago

0.0.0

8 years ago