# EasyREST.js **Repository Path**: Tech_Query/EasyREST.js ## Basic Information - **Project Name**: EasyREST.js - **Description**: 轻量级 JavaScript RESTful 服务端框架 - **Primary Language**: JavaScript - **License**: GPL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 0 - **Created**: 2016-06-28 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 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)` ## 【请求机制】 1. 自定义路由 —— LIFO 2. 前者不匹配、失败,则匹配 FIFO 的 `model` 事件回调 3. 按 RESTful URL 匹配出的 `./data/last_name_of_url` 模块,应为 `DataModel()` 的实现类,并将以上一步的返回值为原始数据来实例化 4. 而后与 HTTP 方法对应的实例方法会被调用,执行数据存取 5. 前面的处理均无效时,会查找 `./public/` 下的同路径文件,并默认以其格式对应的 MIME-Type 响应 6. 若 `Accept` 请求头为 `application/octet-stream`,文件响应则为下载 ## 【内置组件】 ### 文件上传 - [x] 自动监听 `POST /` - [x] 文件存在以其 MINE-Type 主类型为名的 `./public/` 子目录中 - [ ] 支持 SHA-1 校验算法,方便排除重复文件 ## 【典型案例】 - [xMemory 家用云服务器](https://github.com/TechQuery/xMemory) - [黑客马拉松开放平台](https://github.com/FreeCodeCamp-Chengdu/HOP)