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 |
|
10 | Baiji is an ideal candidate for building robust, scalable and secure web things.
|
11 |
|
12 | Features
|
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 |
|
22 | Basic Use Case Preview
|
23 | --------------
|
24 |
|
25 | #### Using ES6 Syntax
|
26 |
|
27 | ```javascript
|
28 | const baiji = require('baiji');
|
29 | const app = baiji('my-example-app');
|
30 |
|
31 | class 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
|
58 | app.use(require('response-time')());
|
59 | // Use express middleware: cookie-parser
|
60 | app.use(require('cookie-parser')());
|
61 |
|
62 | // Use controller
|
63 | app.use(UsersCtrl);
|
64 |
|
65 | // Start app and listen on port 3000
|
66 | app.listen(3000);
|
67 | ```
|
68 |
|
69 | TODOs
|
70 | -----
|
71 |
|
72 | * Add RPC support
|
73 |
|
74 | License
|
75 | -------
|
76 | * [The MIT license](LICENSE)
|