0.0.41 • Published 6 years ago

minmin v0.0.41

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

Apache V2 License

1. Introduction

MinMin is a tiny web framework entirely written in typescript, based on ExpressJS and inspired by Java Web

2. How to use

Getting started

Install minmin

npm install --save minmin

Change tsconfig.json looks like

{
  "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

@Controller('api')
class ApiController {
}

Define request handler

The next step, we need define request handler like this

@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

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

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

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

0.0.41

6 years ago

0.0.40

6 years ago

0.0.39

6 years ago

0.0.38

6 years ago

0.0.37

6 years ago

0.0.36

6 years ago

0.0.35

6 years ago

0.0.34

6 years ago

0.0.33

6 years ago

0.0.32

6 years ago

0.0.31

6 years ago

0.0.30

6 years ago

0.0.29

6 years ago

0.0.28

6 years ago

0.0.27

6 years ago

0.0.26

6 years ago

0.0.25

6 years ago

0.0.22

6 years ago

0.0.21

6 years ago

0.0.20

6 years ago

0.0.19

6 years ago

0.0.18

6 years ago

0.0.17

6 years ago

0.0.16

6 years ago

0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.9

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.5

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago

0.0.1

7 years ago