Hunt framework 2.0.0 released

zoujiaqing zoujiaqing at gmail.com
Tue Jan 29 10:00:22 UTC 2019


The HuntLabs team is happy to announce the release of Hunt 
Framework 2.0.

In Hunt Framework 2.0, we have made many improvements and 
implemented many new features. For example, the old libraries of 
Collie and Kiss are replaced with Hunt-HTTP and Hunt. Here are 
some highlights:

- More powerfull HTTP 1.x parser and APIs.
- HTTP 2.0 support.
- I/O Performance improvements.
- New view template engine.
- Form validation supported.
- Breadcrumbs support in View.
- I18N support in View and Controller.
- Pagination for Entity & EQL supported.
- STOMP-based WebSocket development.
- More Java-alike APIs and modules (like containers, concurrent 
etc.)
- Many new libraries added (like hunt-net, hunt-imf, hunt-sql 
etc.)
- More unit tests and examples.

## Main changes

### Library dependencies changes
| Name | Version |
|--------|--------|
| hunt | 1.0.0 |
| hunt-cache | 0.2.2 |
| hunt-database | 1.1.0 |
| hunt-entity | 2.2.0 |
| hunt-framework | 2.0.0-rc.4 |
| hunt-http | 0.0.14 |
| hunt-imf | 0.0.4 |
| hunt-net | 0.0.14 |
| hunt-security | 0.0.6 |
| hunt-sql | 1.0.5 |
| hunt-stomp | 0.0.3 |
| hunt-trace | 0.1.7 |
| hunt-validation | 0.0.2 |
| boringssl | 0.0.1 |
| dredis | 0.0.9 |
| libmemcached | 1.1.1 |
| openssl | 1.1.6+1.0.1g |
| protobuf | 0.4.0 |
| rocksdb | 0.0.7|

The Collie and Kiss are replaced with Hunt-HTTP and Hunt.

### Configuration changes
1. Array support

test.conf
```ini
servers[0].listen = 8.8.6.1
servers[0].port = 81

servers[1].listen = 8.8.6.2
servers[1].port = 82

ages = 20, 30, 40
users = user01, user02, user03
```

The setting code
```d
@Configuration("server")
struct ServerSettings
{
     @Value("listen")
     string ip = "127.0.0.1";
     ushort port = 8080;
}

class ArrayTestConfig {
     string name;
     int[] ages;
     string[] users;
     ServerSettings[] servers;
}
```

### I18N supported
1. Define language resources in the folder of 
resources/translations/en-us/messages.ini
```ini
WELCOME=Welcome to the world of hunt framework.
VERSION_TITLE=Hunt framework version %s
```

2. Set default langauge in config/application.conf
```ini
hunt.application.defaultLanguage = en-us
hunt.application.languages = zh-cn,en-us
```

3. Using language resources in View
```html
<title>{{ trans("VERSION_TITLE", huntVersion) }}</title>
```

4. Using language resources in Controller
```d
assert(transf("title", "Hunt") == "Hunt Demo");
```


## Breadcrumbs supported
### Initialization
```D
app.onBreadcrumbsInitializing((BreadcrumbsManager breadcrumbs) {
         breadcrumbs.register("home", (Breadcrumbs trail, Object[] 
params...) {
             trail.push("Home", "/home");
         });

         breadcrumbs.register("index.show", (Breadcrumbs trail, 
Object[] params...) {
             trail.parent("home");
             trail.push("About", url("index.show"));
         });
}
```

### Retrieve
```d
view.assign("breadcrumbs", breadcrumbsManager.generate("home"));
```

### Show
```html
     {% if breadcrumbs.defined and breadcrumbs.length>0 %}
     <div class="row">
         <div class="col">
             <ol class="breadcrumb">
                 {% for item in breadcrumbs %}
                     {% if item.link and not loop.last %}
                         <li class="breadcrumb-item"><a href="{{ 
item.link }}">{{ item.title }}</a></li>
                     {% else %}
                         <li class="breadcrumb-item active">{{ 
item.title }}</li>
                     {% endif %}
                 {% endfor %}
             </ol>
         </div>
     </div>
     {% endif %}
```


##  File response
```d
     @Action
     Response download()
     {
         return new FileResponse("/tmp/orders-20190122.zip");
     }
```

Read More: 
https://github.com/huntlabs/hunt-framework/wiki/FileResponse

##  File upload
```D
     @Action
     string upload()
     {
         string message;

         if (request.hasFile("file1"))
         {
             auto file = request.file("file1");

             if (file.isValid())
             {
                 if (file.store("uploads/myfile.zip"))
                 {
                     message = "upload is successed";
                 }
                 else
                 {

                     message = "save as error";
                 }
             }
             else
             {
                 message = "file is not valid";
             }
         }
         else
         {
             message = "not get this file";
         }

         return message;
     }
```

Read More: https://github.com/huntlabs/hunt-framework/wiki/Upload

## Form Validation

### define LoginForm
```D
module app.form.LoginForm;

import hunt;

class LoginForm : Form
{
     mixin MakeForm;

     @Length(6,20)
     string username;

     @Length(8,16)
     string password;
}
```

### Valid in action
```D
@Action
string login(LoginForm loginForm)
{
     string message;
     auto result = loginForm.valid();

     // TODO
     if(!result.isValid)
     {
        message =  "Valid error message : " ~ result.messages();
     }
     else
     {
         message = "OK";
     }

     return message;
}
```

Read More: https://github.com/huntlabs/hunt-framework/wiki/Form


## DataBase changes
1. Pagination
	See: https://github.com/huntlabs/hunt-entity/wiki/Pagination

2. EQL
	https://github.com/huntlabs/hunt-entity/wiki/EQL

3. Validation
	https://github.com/huntlabs/hunt-entity/wiki/Validation

See: 
https://forum.dlang.org/thread/wniszxitzdcuiveqzbap@forum.dlang.org

## HTTP Trace

New modules used to tracing the requests in microservice 
architectures.


## Performance improvements
The core I/O library is refactored, and is called Hunt.
![Benchmark](https://raw.githubusercontent.com/huntlabs/hunt/master/docs/images/benchmark.png)

See: https://github.com/huntlabs/hunt-minihttp


## Examples
hunt-skeleton: https://github.com/huntlabs/hunt-skeleton
hunt-examples: https://github.com/huntlabs/hunt-examples
hunt-minihttp: https://github.com/huntlabs/hunt-minihttp
hunt-http: 
https://github.com/huntlabs/hunt-http/tree/master/examples

## HuntLabs Homepage
https://www.huntlabs.net

## Github repo
https://github.com/huntlabs/hunt-framework

## Gitee repo for Chinese
https://gitee.com/huntlabs/hunt-framework


More information about the Digitalmars-d-announce mailing list