0.0.41 • Published 7 years ago

minmin v0.0.41

Weekly downloads
1
License
MIT
Repository
github
Last release
7 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

7 years ago

0.0.40

7 years ago

0.0.39

7 years ago

0.0.38

7 years ago

0.0.37

7 years ago

0.0.36

7 years ago

0.0.35

7 years ago

0.0.34

7 years ago

0.0.33

7 years ago

0.0.32

7 years ago

0.0.31

7 years ago

0.0.30

7 years ago

0.0.29

7 years ago

0.0.28

7 years ago

0.0.27

7 years ago

0.0.26

7 years ago

0.0.25

7 years ago

0.0.22

7 years ago

0.0.21

7 years ago

0.0.20

7 years ago

0.0.19

7 years ago

0.0.18

7 years ago

0.0.17

7 years ago

0.0.16

7 years ago

0.0.15

8 years ago

0.0.14

8 years ago

0.0.13

8 years ago

0.0.12

8 years ago

0.0.11

8 years ago

0.0.10

8 years ago

0.0.9

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago