UNPKG

1.82 kBMarkdownView Raw
1[Baiji](https://en.wikipedia.org/wiki/Baiji) (白鱀豚 🐬)
2=======
3
4[![Build Status](https://travis-ci.org/baijijs/baiji.svg?branch=master)](https://travis-ci.org/baijijs/baiji)
5
6>> Bring the 🐬(beauty) back to life.
7
8[Baiji](https://github.com/baijijs/baiji) is an easy to use and opinionated micro-framework for writing scalable and REST-like web applications.
9
10Baiji is an ideal candidate for building robust, scalable and secure web things.
11
12Features
13--------
14* Adapters support: [Express](https://github.com/expressjs/express), [Socket.io](https://github.com/socketio/socket.io), more supports will comming soon
15* Hooks, enabling the power of scalability of your api method
16* Modern Controller syntax
17* Smart routes sorter
18* Sweet debug info
19* Built-in parameter filter
20* Entities - a simple Facade to use with your models and API
21
22Basic Use Case Preview
23--------------
24
25#### Using ES6 Syntax
26
27```javascript
28const baiji = require('baiji');
29const app = baiji('my-example-app');
30
31class UsersCtrl extends baiji.Controller {
32 constructor() {
33 super();
34 // Use before actions
35 this.beforeAction('signInRequired');
36 }
37
38 initConfig() {
39 return {
40 search: {
41 description: 'Search users...',
42 route: { path: '/', verb: 'get' }
43 }
44 }
45 }
46
47 signInRequired(ctx, next) {
48 if (ctx.state.isSignedIn()) return next();
49 ctx.done({ error: 'Unauthorized' });
50 }
51
52 search(ctx, next) {
53 ctx.done([{ username: 'lyfeyaj', gender: 1 }], next);
54 }
55}
56
57// Use express middleware: response-time
58app.use(require('response-time')());
59// Use express middleware: cookie-parser
60app.use(require('cookie-parser')());
61
62// Use controller
63app.use(UsersCtrl);
64
65// Start app and listen on port 3000
66app.listen(3000);
67```
68
69TODOs
70-----
71
72* Add RPC support
73
74License
75-------
76* [The MIT license](LICENSE)