npm install abox --save
action.ts
import {Action} from "abox";
@Action({ name: "ping" })
export class Ping {
constructor(public message: string) {
}
}
@Action({ name: "pong" })
export class Pong {
constructor(public message: string) {
}
}
app.ts
import {Api} from "abox";
import {Ping, Pong} from "./actions";
const api = new Api();
api
.on(Ping)
.handle((context, data) => {
context.done(new Pong(data.message));
});
api
.on(Pong)
.handle((context, data) => {
console.log("Pong:", data.message);
context.done();
});
export = api;