Skip to content
A simple Nodejs framework made in Typescript to build REST APIs
TypeScript
Branch: develop
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode
dist/lib
src
.gitignore
.npmignore
.travis.yml
CODE_OF_CONDUCT.md
LICENSE.md
README.md
README_pt-BR.md
package.json
tsconfig-es5.json
tsconfig.json

README.md

Português / English

ProtonType

A simple framework made with TypeScript.

Build your Nodejs APIs with Classes, Methods, Annotations, ORM ...

Documentation

Instalation

npm install protontype --save

Models

Uses TypeORM by default database manipulation. But any framework can be used.

@Entity()
export class TasksModel {
    @PrimaryGeneratedColumn()
    id: number;
    @Column({ nullable: true })
    title: string;
    @Column()
    done: boolean;
    @Column()
    userId: number;
}

Middlewares

Supports middlewares implementation

export class TasksMiddleware extends BaseMiddleware {
    @Middleware()
    printTaskTitle(params: MiddlewareFunctionParams) {
        cosole.log(params.req.body.title);
        params.next();
    }
}

Router

CRUD basic routes already implemented in CrudRouter

 @RouterClass({
    baseUrl: "/tasks",
    model: TasksModel,
    middlewares: [new TasksMiddleware()]
})
export class TasksRouter extends CrudRouter {
    /*
    GET / - Lists all records
    POST / - Creates a records
    GET /:id - Queries a records
    PUT /:id - Updates a records
    DELETE /:id - Removes a records
    */

    //New custom routes ....
}

Or can implements custom routes

 @RouterClass({
    baseUrl: "/tasks",
    model: TasksModel,
    middlewares: [new TasksMiddleware()]
})
export class TasksRouter extends BaseRouter {
    @Route({
        endpoint: '/test/msg',
        method: Method.GET,
        middlewares: [new OtherMiddleware()]
    })
    routeTest(params: RouterFunctionParams) {
        console.log("Hello!");
    }
}

Database manipulation

let tasksRepository = TypeORMDB.getBD().getRepository(TasksModel);
let tasks = await tasksRepository.find();

Starting application

new ProtonApplication()
    .addRouterAs(TasksRouter)
    .addMiddlewareAs(SomeoneGlobalMiddleware)
    .start();

Examples

Development version

npm install protontype@dev --save
You can’t perform that action at this time.