0.0.5 • Published 9 years ago

cass v0.0.5

Weekly downloads
4
License
MIT
Repository
github
Last release
9 years ago

Cass

It rhymes with jax-rs.

A convenience layer to build JSON APIs using Quinn.

import { createServer } from 'http';

import cass from 'cass';
import Boom from 'boom'; // `boom` is whitelisted for providing status codes
import { Inject, Provides } from 'nilo';
import { PUT } from 'wegweiser';
import quinn from 'quinn';

import RadioTuner from './tuner';

@Inject(RadioTuner)
class RadioResource {
  constructor(tuner) { this.tuner = tuner; }

  @PUT('/radio/:station')
  setStation(req, params) {
    if (params.station.length > 10) {
      throw new Boom(400, 'Invalid station, max length is 10');
    }
    this.tuner.tuneTo(params.station);
    return { ok: true };
  }
}

const app = cass(RadioResource);
app.graph.scan({ // "scan for dependency providers"
  @Provides(RadioTuner)
  getRadioTuner() {
    return new RadioTuner(process.env.RADIO_FILE || '/dev/null');
  }
});

createServer(quinn(app)).listen(3000);
0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago