Skip to content

dingaiminGIT/blade

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Based on Java8 + Netty4 to create lightweight, high-performance, simple and elegant Web framework 😋

Spend 1 hour to learn it to do something interesting, a Spring in addition to the framework of the best choice.

🐾 Quick Start | 📘 Blade In Action | 🎬 Video Tutorial | 🌚 Contribution | 💰 Donate | 🇨🇳 简体中文


What Is Blade?

Blade is a pursuit of simple, efficient Web framework, so that JavaWeb development even more powerful, both in performance and flexibility. If you like to try something interesting, I believe you will love it. If you think this item is good can star support or donate it 😊

Features

  • A new generation of MVC frameworks that do not depend on more libraries
  • Get rid of SSH's bloated, modular design
  • source less than 500kb, learning is also simple
  • Restful style routing design
  • template engine support, view development more flexible
  • high performance, 100 concurrent tps 6w/s
  • Run the JAR package to open the web service
  • Streaming API style
  • supports plug-in extensions
  • support webjars resources
  • built-in a variety of commonly used middleware
  • Built-in JSON output
  • JDK8 +

Overview

» Simplicity: The design is simple, easy to understand and doesn't introduce many layers between you and the standard library. The goal of this project is that the users should be able to understand the whole framework in a single day.
» Elegance: blade supports the RESTful style routing interface, has no invasive interceptors and provides the writing of DSL grammar.
» Easy deploy: support maven package jar file running.

Get Start

Grab via Maven

<dependency>
	<groupId>com.bladejava</groupId>
	<artifactId>blade-mvc</artifactId>
	<version>2.0.2-beta3</version>
</dependency>

or Gradle:

compile 'com.bladejava:blade-mvc:2.0.2-beta3'

Write main method, lets Hello World

public static void main(String[] args) {
    Blade.me().get("/", (req, res) -> {
        res.text("Hello Blade");
    }).start();
}

Using browser open http://localhost:9000 so you can see the first Blade application!

API Example

public static void main(String[] args) {
    // Create Blade,using GET、POST、PUT、DELETE
    Blade.me()
        .get("/user/21", getting)
        .post("/save", posting)
        .delete("/remove", deleting)
        .put("/putValue", putting)
        .start();
}

REST URL Parameters

public static void main(String[] args) {
    Blade blade = Blade.me();
    // Create a route: /user/:uid
    blade.get("/user/:uid", (request, response) -> {
		Integer uid = request.pathInt("uid");
		response.text("uid : " + uid);
	});
	
    // Create two parameters route
    blade.get("/users/:uid/post/:pid", (request, response) -> {
		Integer uid = request.pathInt("uid");
		Integer pid = request.pathInt("pid");
		String msg = "uid = " + uid + ", pid = " + pid;
		response.text(msg);
	});
	
    // Start blade
    blade.start();
}

Form Parameters

public static void main(String[] args) {
    Blade.me().get("/user", ((request, response) -> {
         Optional<Integer> ageOptional = request.queryInt("age");
         ageOptional.ifPresent(age -> System.out.println("age is:" + age));
     })).start();
}

Upload File

public void upload(@MultipartParam FileItem fileItem){
    byte[] data = fileItem.getData();
    // Save the temporary file to the specified path
    Files.write(Paths.get(filePath), data);
}

Or

public void upload(Request request){
    request.fileItem("img").ifPresent(fileItem -> {
        byte[] data = fileItem.getData();
        // Save the temporary file to the specified path
        Files.write(Paths.get(filePath), data);              
    });
}

Before hook

public static void main(String[] args) {
    // All requests are exported before execution before
    Blade.me().before("/*", (request, response) -> {
        System.out.println("before...");
    }).start();
}

How easy it all looks, but the features above are the tip of the iceberg, and there are more surprises to see in the documentation and sample projects:

Use the Blade site

Update

update log

Contact

Contributor

Thank you very much for the developers to help in the project, if you are willing to contribute, welcome!

Licenses

Please see Apache License

About

🚀 a simple, elegant mvc framework! website →

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%