# minmin

> MinMin Web Framework

Latest version **0.0.41** (published 2018-09-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install minmin
pnpm add minmin
yarn add minmin
bun add minmin
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.41 |
| Published | 2018-09-15 |
| First published | 2017-09-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 11 |
| Unpacked size | 90.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | minhdtb |
| Maintainers | minhdtb |

## Links

- npm: https://www.npmjs.com/package/minmin
- Repository: https://github.com/minhdtb/minmin
- Homepage: https://github.com/minhdtb/minmin#readme
- Issues: https://github.com/minhdtb/minmin/issues
- npm.io page: https://npm.io/package/minmin

## Dependencies (11)

- [cors](https://npm.io/package/cors.md) ^2.8.4
- [helmet](https://npm.io/package/helmet.md) ^3.8.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.5
- [moment](https://npm.io/package/moment.md) ^2.19.3
- [express](https://npm.io/package/express.md) ^4.15.4
- [winston](https://npm.io/package/winston.md) ^2.3.1
- [body-parser](https://npm.io/package/body-parser.md) ^1.18.1
- [compression](https://npm.io/package/compression.md) ^1.7.0
- [cookie-parser](https://npm.io/package/cookie-parser.md) ^1.4.3
- [express-session](https://npm.io/package/express-session.md) ^1.15.5
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.10

## Recent versions

- 0.0.41 (latest) — 2018-09-15
- 0.0.40 — 2018-09-12
- 0.0.39 — 2018-09-12
- 0.0.38 — 2018-09-12
- 0.0.37 — 2018-08-13
- 0.0.36 — 2018-08-10
- 0.0.35 — 2018-08-07
- 0.0.34 — 2018-08-06
- 0.0.33 — 2018-08-06
- 0.0.32 — 2018-08-03
- 0.0.31 — 2018-08-03
- 0.0.30 — 2018-08-03
- 0.0.29 — 2018-08-03
- 0.0.28 — 2018-08-03
- 0.0.27 — 2018-08-03
- … 20 more at https://npm.io/package/minmin/versions

## README

<p align="center"><img align="center" src="https://github.com/minhdtb/minmin/blob/master/images/minmin-logo.png"/></p>

[![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

---
_Source: https://npm.io/package/minmin · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
