Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/protontype/protontype

A simple Nodejs framework made in Typescript to build REST APIs
https://github.com/protontype/protontype

espressjs express nodejs protontype rest rest-api server typeorm typescript

Last synced: about 5 hours ago
JSON representation

A simple Nodejs framework made in Typescript to build REST APIs

Awesome Lists containing this project

README

        

[Português](README.md) / **English**
# ProtonType



















A simple framework made with TypeScript.

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

## Documentation
- [Full documentation](https://protontype.github.io/)

## Instalation
```bash
npm install protontype --save
```

## Models
Uses [TypeORM](http://typeorm.io/#/) by default database manipulation. But any framework can be used.

```typescript
@Entity()
export class TasksModel {
@PrimaryGeneratedColumn()
id: number;
@Column({ nullable: true })
title: string;
@Column()
done: boolean;
@Column()
userId: number;
}
```
## Middlewares
Supports middlewares implementation

```typescript
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```

```typescript
@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
```typescript
@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
```typescript
let tasksRepository = TypeORMDB.getBD().getRepository(TasksModel);
let tasks = await tasksRepository.find();
```

## Starting application

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

## Examples
- [Basic example](https://github.com/protontype/protontype-sample)

- [Sequelize module example](https://github.com/protontype/protontype-sequelize-sample)

## Development version
```bash
npm install protontype@dev --save
```