Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/minhdtb/minmin
MinMin - a tiny typescript web framework based on Express
https://github.com/minhdtb/minmin
framework minimalist minmin spring spring-mvc typescript web
Last synced: 2 months ago
JSON representation
MinMin - a tiny typescript web framework based on Express
- Host: GitHub
- URL: https://github.com/minhdtb/minmin
- Owner: minhdtb
- License: mit
- Created: 2017-09-22T09:52:29.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-07T07:42:37.000Z (about 2 years ago)
- Last Synced: 2024-09-29T08:41:01.900Z (3 months ago)
- Topics: framework, minimalist, minmin, spring, spring-mvc, typescript, web
- Language: TypeScript
- Homepage:
- Size: 1.21 MB
- Stars: 16
- Watchers: 3
- Forks: 5
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![Apache V2 License](http://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/minhdtb/minmin/blob/master/LICENSE)
## 1. Introduction
MinMin is a tiny web framework entirely written in typescript, based on [ExpressJS](https://expressjs.com/) and inspired by Java Web
## 2. How to use
### Getting started
#### Install minmin
```npm install --save minmin```
Change tsconfig.json looks like
```json
{
"compilerOptions": {
"lib": [
"dom",
"es2015"
],
"target": "es5",
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
}
}
```#### Define controller
Firstly we create ```ApiController.ts``` file then define controller with ```base url``` is ```/api```
```ts
@Controller('api')
class ApiController {
}
```#### Define request handler
The next step, we need define request handler like this
```ts
@Controller('api')
class ApiController {@Post('login')
private async login(@Data('username') username: string,
@Data('password') password: string) {
let user = await User.findOne({username: username});
if (user) {
let compare = await user.comparePassword(password);
if (compare) {
return new Result('user', user);
} else {
return new Error(401, "Invalid username or password.");
}
} else {
return new Error(404, "Username not found.");
}
}
}
```
The upper code is equivalent to http method handler in expressjs like bellow
```js
app.post('/api/login', function(req, res) {
var username = req.body.username
var password = req.body.password
...
})
```#### Start server
The last step is starting web server
```ts
import {WebServer} from "minmin"
import './controllers/ApiController' // import the controller here (very important)const server = new WebServer();
server.setPort(3000);
server.start();
```### Support Dependency Injection
Support dependency injection since version 0.0.32
```ts
import {Controller, Service, Inject} from "minmin"@Service()
class MyService {action(): void {
}
}@Controller('api')
class ApiController {@Inject()
myService: MyService;
}```
## 3. Decorators list
### Methods
```@Get```
```@Post```
```@Put```
```@Delete```### Parameters
```@Param```
```@Query```
```@Data```
```@Session``` (deprecated)
```@Request```### Dependency Injection
```@Inject```
```@Service```## 4. Classes list
```WebServer```
```Result```
```Error```
```View```
```Redirect```## 5. Template and demo
#### simple: https://github.com/minhdtb/minmin-template
#### with NuxtJS: https://github.com/minhdtb/minmin-nuxt-template