0.3.0 • Published 9 years ago

exoid-router v0.3.0

Weekly downloads
-
License
MIT
Repository
-
Last release
9 years ago

Exoid Router

Create Exoid compatible APIs

router = require 'exoid-router'

authed = (handler) ->
  unless handler?
    return null

  (body, req, rest...) ->
    unless req.isAuthed
      router.throw status: 401, message: 'Unauthorized'

    handler body, req, rest...

routes = router
# Public Routes
.on 'auth.login', AuthCtrl.login

# Authed Routes
.on 'users.getMe', authed UserCtrl.getMe

# As Express Middleware
app.post '/exoid', routes.asMiddleware()

# Joi schema validation
Joi = require 'joi'
# validate {presence: 'required', convert: false}
router.assert('str', Joi.string())

# manual throw, error sent to client
router.throw message: 'invalid api call'

routes.resolve path, body, req
.then ({result, error, cache}) -> null
0.3.0

9 years ago

0.2.6

10 years ago

0.2.5

10 years ago

0.2.4

10 years ago

0.2.3

10 years ago

0.2.2

11 years ago

0.2.1

11 years ago

0.2.0

11 years ago

0.1.0

11 years ago