Socket
Book a DemoInstallSign in
Socket

easy-rest

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easy-rest

Lightweight RESTful HTTP Server

latest
npmnpm
Version
0.6.0
Version published
Maintainers
1
Created
Source

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 校验算法,方便排除重复文件

【典型案例】

  • xMemory 家用云服务器

  • 黑客马拉松开放平台

Keywords

RESTful

FAQs

Package last updated on 02 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts