Rtf restful framework for node
Sundae is a light weight api framework based on express, but more intesting than express.
app = sundae express()
# You can definitely declare the path to route
# Router support all methods exported from `methods` module (get/post/put/delete/options/etc...)
# The route pattarn is something like `app[method] path, to: {controller}#{action}`
app.get '/', to: 'home#index'
# Post method
app.post '/', to: 'home#create'
# Resource route
# Then you also got the `resource` function to do the above things more restfully
app.resource 'home', only: ['create', 'read']
# Router options
# Router support some options like
# `only`: Only use actions listed in the only option
# `except`: Omit the actions in except option
# `to`: Alias to `ctrl#action`
# `ctrl`: Controller name
# `action`: Action name
# The example below shows mapping a group of `user` restful apis to the admin controller
app.resource 'user', ctrl: 'admin'
app = sundae express()
app.controller 'home', ->
# Mixin permission functions
@mixin require './mixins/permission'
# Request should contain these params
@ensure 'user-agent', only: 'index'
# These filters will execute before controller.index action
@before 'checkAgent'
# We'll filter the useless key of the callback data
@select '-useless'
# This assembler function is declared in home mixer
@after 'changeName'
# This is a controller action
# You can call this function through router
@action 'index', (req, res, callback) ->
callback null,
welcome: 'Hello World'
"user-agent": req.get('user-agent')
useless: 'useless message'
# This is a filter function looks like controller actions
# You can call this function from router
# But most time you shouldn't do this
@action 'checkAgent', (req, res, callback) ->
userAgent = req.get('user-agent')
# If the first param of callback is not null
# controller.index will not be called
return callback(new Error('GOD! WHY ARE YOU STILL USING IE?')) if userAgent.match /MSIE/
callback()
only
only keep the specific actionsexcept
without the specific actions
only
only the specific actions will apply hooksexcept
all actions will apply hooks without the except actionsparallel
hooks will be parallel executed, the default mode is series (execute one by one)
- Add
req.getParams
function to get the original param given by user
- Support stand alone application build with sundae
- Set app.request/response to an constructor when using sundae without express
- Add
has
function on request
- Add
mask
decorator;
- Add
least
decorator.
- Apply
sundae
on the application level. - New router, controller, action patterns.
- remove
express
in dependencies, you should require express by yourself in application - change the initialize functions, for more infomation, check the 'examples' directory
- remove cli mode
- use some options in the resource directive, e.g.
ctrl
,action
...
- fix expand of req.headers, req.cookies etc.
- remove wrap of actions, every action will receive three arguments: req, res, callback
- hooks do not apply on each action now, they are only bind to actions emit by router
- embed err1st package
- ignore lib directory in development mode
- clone _before/_after actions when extends from parent class
- give up using
transfer
option, it's not a good idea, find another way
- check invalid params in router
- error support for 404 and 500 response
- change the statement of decorators
- change router to singleton, add router _stack
- fix post decorator bug
- add assembler, post decorators
- fix mixer loader
- auto load mixers
- add more comments in demo controllers
- fix request reset params bug
- fix cli init crash
- new beginning of sundae framework