# 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

Latest version **1.0.3** (published 2021-11-16) · 0 weekly downloads

## Install

```sh
npm install ette
pnpm add ette
yarn add ette
bun add ette
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2021-11-16 |
| First published | 2018-10-14 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 131.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | boycgit |
| Maintainers | jscon |

## Links

- npm: https://www.npmjs.com/package/ette
- Repository: https://github.com/common-ide/ette-kit.git#main
- Homepage: https://github.com/common-ide/ette-kit/tree/main#readme
- Issues: https://github.com/common-ide/ette-kit/issues
- npm.io page: https://npm.io/package/ette

## Dependencies (3)

- [url-parse](https://npm.io/package/url-parse.md) ^1.5.3
- [http-status-codes](https://npm.io/package/http-status-codes.md) ^2.1.4
- [wolfy87-eventemitter](https://npm.io/package/wolfy87-eventemitter.md) ^5.2.5

## Recent versions

- 1.0.3 (latest) — 2021-11-16
- 1.0.2 — 2021-11-16
- 1.0.1 — 2021-10-29
- 0.3.10 — 2019-05-22
- 0.3.9 — 2019-02-27
- 0.3.8 — 2019-02-13
- 0.3.7 — 2019-02-12
- 0.3.6 — 2019-02-12
- 0.3.5 — 2019-02-12
- 0.3.4 — 2019-01-20
- 0.3.3 — 2019-01-18
- 0.3.2 — 2018-11-13
- 0.3.1 — 2018-11-13
- 0.3.0 — 2018-11-13
- 0.2.2 — 2018-10-16
- … 2 more at https://npm.io/package/ette/versions

## README

# 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) [![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg?v=103)](https://opensource.org/licenses/mit-license.php) [![npm version](https://badge.fury.io/js/ette.svg)](https://badge.fury.io/js/ette)

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

```bash
npm install ette --save
```

```javascript
var Ette = require('ette');
```

### Global object

Include the pre-built script.

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

```

## Build & test

```bash
npm run build
```

```bash
npm test
```

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


```js
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:

```sh
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

```bash
npm run doc
```

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

## License

[MIT](LICENSE).

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