# easy-rest

> Lightweight RESTful HTTP Server

Latest version **0.6.0** (published 2017-06-02) · GPL-2.0 license · 0 weekly downloads

## Install

```sh
npm install easy-rest
pnpm add easy-rest
yarn add easy-rest
bun add easy-rest
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.6.0 |
| Published | 2017-06-02 |
| First published | 2017-02-09 |
| Weekly downloads | 0 |
| License | GPL-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | shiy007@qq.com |
| Maintainers | tech_query |
| Keywords | RESTful, HTTP, server, JavaScript |

## Links

- npm: https://www.npmjs.com/package/easy-rest
- Repository: https://git.oschina.net/Tech_Query/EasyREST.js
- npm.io page: https://npm.io/package/easy-rest

## Dependencies (2)

- [formidable](https://npm.io/package/formidable.md) ^1.1.1
- [node-session](https://npm.io/package/node-session.md) ^1.2.1

## Recent versions

- 0.6.0 (latest) — 2017-06-02
- 0.4.2 — 2017-05-22
- 0.4.0 — 2017-05-15
- 0.3.5 — 2017-05-14
- 0.3.0 — 2017-02-10
- 0.2.0 — 2017-02-09

## 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)

---
_Source: https://npm.io/package/easy-rest · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
