1.0.33 • Published 6 years ago

apicorev3 v1.0.33

Weekly downloads
73
License
ISC
Repository
-
Last release
6 years ago

CoreAPI

A library for build REST API in Node.js using in some personal project.

Installation

IMPORTANT: Requires Node.js 6 or newer.

npm install apicorev3

Quick Example

const apicorev3 = require('apicorev3');

apicorev3(core => {
    // 1. Declare some controller with public API.

    class HelloController extends core.api.Controller {
        constructor() {
            super();
            this.namespace('api/v1', () => {
                this.resources('hello'); // => /api/v1/hello
            });
            // this.allowAnonymous = true;
            // this.isHidden = true;
        }

        //@api [default] /api/v1/hello/getmessage
        getMessage() {
            return { info: 'Hello World!' };
        }
    }

    // 2. Declare and start server.

    var app = core.api.startup(CGlobal => {
        CGlobal.config = { server: { port: 9000 } };
    });

    var server = app.newServer({ port: app.config.server.port }, (err, info) => {
        if (err) {
            console.log('server.err =>' + err.message);
        } else {
            console.log('server.info =>' + info.address().port);
        }
    });

    server.register(appBuilder => {
        appBuilder.onLoad(() => {
            console.log('The app has load!!!');
        });

        appBuilder.onMount((controller) => {
            console.log(controller + ' has mounted!');
        });

        appBuilder.onRoute((handler) => {
            console.log(`method, urlPath => ${handler.method} ${handler.urlPath}`);
        });

        // normaly you only must call.
        // appBuilder.load();

        // this is for sample.
        appBuilder.manager.add(new HelloController());
        // appBuilder.manager.register(new HelloController(), { 'getMessage': [['post', 'get'], 'message'] });
    });

    // server.use(middleContext => {
    //     // middleContext.req|res|next
    //
    //     middleContext.accept((req, res, next) => {
    //         console.log('> call to the middle function');
    //         next();
    //     });
    // });

    return server;
});
1.0.33

6 years ago

1.0.32

6 years ago

1.0.31

6 years ago

1.0.30

6 years ago

1.0.29

7 years ago

1.0.28

7 years ago

1.0.27

7 years ago

1.0.26

7 years ago

1.0.25

7 years ago

1.0.24

7 years ago

1.0.23

7 years ago

1.0.22

7 years ago

1.0.21

7 years ago

1.0.20

7 years ago

1.0.19

7 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.14

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago