easy-rest v0.6.0
EasyREST.js
轻量级 JavaScript RESTful 服务端框架,NPM 包名 easy-rest。
【主要模块】
数据模型 抽象类
DataModel(context, data)DataModel.Hash2SQL(data, assign, separator)DataModel.prototype.valueOf()DataModel.prototype.search( query )DataModel.prototype.append()DataModel.prototype.update()DataModel.prototype.remove()
多条件观察者对象
Observer.prototype.on(event, callback)Observer.prototype.before(event, callback)Observer.prototype.emit(event, callback)Observer.prototype.off(event, callback)Observer.prototype.one(event, callback)Observer.prototype.valueOf(event, key)
RESTful 应用对象
RestApp( option )继承自Observer()RestApp.prototype.get(url_pattern, callback)RestApp.prototype.post(url_pattern, callback)RestApp.prototype.put(url_pattern, callback)RestApp.prototype.delete(url_pattern, callback)RestApp.prototype.all(url_pattern, callback)RestApp.prototype.trig(type, data)
【请求机制】
自定义路由 —— LIFO
前者不匹配、失败,则匹配 FIFO 的
model事件回调按 RESTful URL 匹配出的
./data/last_name_of_url模块,应为DataModel()的实现类,并将以上一步的返回值为原始数据来实例化而后与 HTTP 方法对应的实例方法会被调用,执行数据存取
前面的处理均无效时,会查找
./public/下的同路径文件,并默认以其格式对应的 MIME-Type 响应若
Accept请求头为application/octet-stream,文件响应则为下载
【内置组件】
文件上传
- 自动监听 
POST / - 文件存在以其 MINE-Type 主类型为名的 
./public/子目录中 - 支持 SHA-1 校验算法,方便排除重复文件