Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/no0dles/abox


https://github.com/no0dles/abox

Last synced: 25 days ago
JSON representation

Awesome Lists containing this project

README

        

# abox - Api Toolbox
[![Build Status](https://travis-ci.org/no0dles/abox.svg?branch=master)](https://travis-ci.org/no0dles/abox)
[![npm version](https://badge.fury.io/js/abox.svg)](https://badge.fury.io/js/abox)
[![codecov](https://codecov.io/gh/no0dles/abox/branch/master/graph/badge.svg)](https://codecov.io/gh/no0dles/abox)

## Quickstart

### Installation
```
npm install abox --save
```

### Code Example
messages.ts
```typescript
import {Key} from "abox";

@Key("ping")
export class Ping {
constructor(public message: string) {

}
}

@Key("pong")
export class Pong {
constructor(public message: string) {

}
}
```

app.ts
```typescript
import {Api} from "abox";
import {Ping, Pong} from "./messages";

const api = new Api();

api
.on(Ping)
.do((ping, context) => {
context
.emit(new Pong(ping.message))
.done();
});

api
.on(Pong)
.do((pong, context) => {
console.log("Pong:", pong.message);
context.done();
});

export = api;
```