New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ette

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ette

[![Build Status](https://travis-ci.org/boycgit/ette.svg?branch=master)](https://travis-ci.org/boycgit/ette) [![Coverage Status](https://coveralls.io/repos/github/boycgit/ette/badge.svg?branch=master)](https://coveralls.io/github/boycgit/ette?branch=master

1.0.3
latest
Source
npm
Version published
Maintainers
1
Created
Source

ette

Build Status Coverage Status MIT Licence npm version

Event-Driver message communication framework, koa style, to make browser web applications and APIs more enjoyable to write and maintain.

  • written in Typescript
  • used with koa style
  • fully tested

Installation

Node.js / Browserify

npm install ette --save
var Ette = require('ette');

Global object

Include the pre-built script.

<script src="./dist/index.umd.min.js"></script>

Build & test

npm run build
npm test

Usage

https://repl.it/@boycgit/ette-usage-1

var App = require('ette');
const app = new App({domain: 'any-domain-name'});
const client = app.client;

app.use((ctx, next) => {
  const req = ctx.request;
  console.log('request:'+ JSON.stringify(req.toJSON()));

  //   相当简单的路由
  if (req.path === '/users/1') {
    ctx.response.body = { hello: 'jscon' };
  } else if (req.path === '/users/2') {
    ctx.response.body = { hello: 'nancy' };
  } else {
    ctx.response.body = { hello: 'anonymity' };
  }
  
  ctx.response.status = 200;

  return next();
});

client.post(`/users/4`)
  .then(res => {
    console.log('/users/4:' + JSON.stringify(res));
  })
  .catch(err => {
    console.log(err);
  });

console output will be:

request:{"method":"POST","url":"//any-domain-name/users/4","type":"JSON"}

/users/4:{"status":200,"statusText":"OK","type":"JSON","body":{"hello":"anonymity"}}

Document

参考 koa-router: https://github.com/koajs/router/blob/master/API.md

npm run doc

then open the generated out/index.html file in your browser.

License

MIT.

FAQs

Package last updated on 16 Nov 2021

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