Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/protontype/protontype
- Owner: protontype
- License: mit
- Created: 2016-08-17T01:14:51.000Z (over 8 years ago)
- Default Branch: develop
- Last Pushed: 2018-09-06T14:22:54.000Z (about 6 years ago)
- Last Synced: 2024-11-06T22:57:42.202Z (13 days ago)
- Topics: espressjs, express, nodejs, protontype, rest, rest-api, server, typeorm, typescript
- Language: TypeScript
- Homepage: https://protontype.github.io/
- Size: 681 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[Português](README.md) / **English**
# ProtonTypeA 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
```