Skip to content

基于jdk的httpserver封装的轻量级http服务端,支持8以上任何版本,支持native

License

Notifications You must be signed in to change notification settings

kongweiguang/KHTTP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KHTTP

基于jdk内部的httpserver封装的轻量级http服务端

Apache 2 jdk-8+



特点

  • 非常轻量,代码简单,大小只有12k
  • api友好,用的很爽
  • 支持8+以上的所有版本,支持native构建

使用方式

Maven

<dependency>
    <groupId>io.github.kongweiguang</groupId>
    <artifactId>kHTTP</artifactId>
    <version>0.0.3</version>
</dependency>

Gradle

implementation 'io.github.kongweiguang:KHTTP:0.0.3'

Gradle-Kotlin

implementation("io.github.kongweiguang:kHTTP:0.0.3")

例子

public class Test1 {
    public static void main(String[] args) {
        KHTTP.of()
                .executor(Executors.newCachedThreadPool())
                .web("/Users/kongweiguang/Desktop/hegui/xm/gs")
                .get("/get", (req, res) -> {
                    final MultiValueMap<String, String> params = req.params();
                    res.send("hello").send("world");
                })
                .post("/post", ((req, res) -> {
                    final String str = req.str();
                    System.out.println("str = " + str);

                    res.send("{\"key\":\"i am post res\"}");
                }))
                .post("/upload", (req, res) -> {

                    final MultiValueMap<String, String> params = req.params();

                    final Map<String, List<UpFile>> files = req.fileMap();
                })
                .get("/xz", new Handler() {
                    @Override
                    public void doHandler(final Req req, final Res res) throws IOException {
                        res.file("k.txt", Files.readAllBytes(Paths.get("D:\\k\\k.txt")));
                    }
                })
                .ok(8080);

    }
}

About

基于jdk的httpserver封装的轻量级http服务端,支持8以上任何版本,支持native

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages