All Projects → liujunlingx → LightWebServer

liujunlingx / LightWebServer

Licence: other
Java web server using NIO, compatible with http1.1 and support simple MVC function.

Programming Languages

java
68154 projects - #9 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to LightWebServer

Mineserver
🚗 http server implementation for java native nio api
Stars: ✭ 179 (+371.05%)
Mutual labels:  nio, http-server
T Io
解决其它网络框架没有解决的用户痛点,让天下没有难开发的网络程序
Stars: ✭ 1,331 (+3402.63%)
Mutual labels:  nio, http-server
huanhuan-blog
一个java版本freemarker的小博客项目
Stars: ✭ 19 (-50%)
Mutual labels:  spring-mvc
fastglue
Fastglue is an opinionated, bare bones wrapper that glues together fasthttp and fasthttprouter to act as a micro HTTP framework.
Stars: ✭ 71 (+86.84%)
Mutual labels:  http-server
SQLiteQueryServer
Bulk query SQLite database over the network
Stars: ✭ 48 (+26.32%)
Mutual labels:  http-server
aqua
A minimal and fast 🏃 web framework for Deno
Stars: ✭ 219 (+476.32%)
Mutual labels:  http-server
spotifyApiSpring
Spring-boot MVC application consuming Spotify's REST API
Stars: ✭ 28 (-26.32%)
Mutual labels:  spring-mvc
product-catalog-spring-mvc-demo
A Product Catalog Demonstration Project Using Spring MVC and Mongo DB
Stars: ✭ 16 (-57.89%)
Mutual labels:  spring-mvc
rawhttp
HTTP library to make it easy to deal with raw HTTP.
Stars: ✭ 156 (+310.53%)
Mutual labels:  http-server
snunit
Scala Native HTTP server based on NGINX Unit
Stars: ✭ 87 (+128.95%)
Mutual labels:  http-server
vscode-open-in-default-browser
Open In Default Browser
Stars: ✭ 22 (-42.11%)
Mutual labels:  http-server
twitter-emulation
Twitter emulation in Java and Angular
Stars: ✭ 31 (-18.42%)
Mutual labels:  spring-mvc
go-import-server
HTTP server for canonical "go get" import path
Stars: ✭ 29 (-23.68%)
Mutual labels:  http-server
web-benchmarks
A set of HTTP server benchmarks for Golang, node.js and Python with proper CPU utilization and database connection pooling.
Stars: ✭ 22 (-42.11%)
Mutual labels:  http-server
SpringSecuritySocialLoginExample
This application will provider user to login with social login( facebook, linkedin and twitter) and form login as well.
Stars: ✭ 39 (+2.63%)
Mutual labels:  spring-mvc
Library
Online Library Management. User can search, check in, checkout book. System adds fines automatically if the book is not checked in by due date
Stars: ✭ 27 (-28.95%)
Mutual labels:  spring-mvc
yams
YAMS: Awesome MIPS Server
Stars: ✭ 17 (-55.26%)
Mutual labels:  http-server
python-simple-http-server
A super light way HTTP server written by python, support websocket and coroutine.
Stars: ✭ 26 (-31.58%)
Mutual labels:  http-server
project-tracking-system-backend-app
Enterprise project tracker, tracks commits done by employees after getting assigned to a couple of projects by their managers
Stars: ✭ 62 (+63.16%)
Mutual labels:  spring-mvc
HTTP-Reverse-Shell
An HTTP Reverse Shell in Python
Stars: ✭ 48 (+26.32%)
Mutual labels:  http-server

LightWebServer

LightWebServer是一个轻量级的嵌入式web服务器,同时提供了简单的mvc框架。

Required

  • Java version >= 1.8

Install

  1. mvn -Dmaven.test.skip=true clean install
  2. include maven dependency
<dependencies>
    <dependency>
        <groupId>com.lightwebserver</groupId>
        <artifactId>lightwebserver</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
</dependencies>

Usage

LightWebServer is similar to Spring MVC.

请求映射

@Controller --> 类似Spring MVC中的@Controller

@WebPath --> 类似Spring MVC中的@RequestMapping

参数注入

  • @QueryParam 得到GET参数
  • @FormParam 得到x-www-form-urlencoded类型POST方法的参数
  • @MultiPartData 得到multipart/form-data类型POST方法得到的参数
  • HttpServletRequest无需注解即可注入
  • 目前只能返回com.light.http.responses.Response

Example

  1. Create controller
import com.light.http.HttpMethod;
import com.light.http.HttpStatus;
import com.light.http.requests.MimeData;
import com.light.http.responses.FileResponse;
import com.light.http.responses.JsonResponse;
import com.light.http.responses.Response;
import com.light.mvc.annotations.*;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@Controller
public class HelloWorldController {

    // GET
    @WebPath("/testGet")
    public Response testGet(@QueryParam(value = "name",required = true)String name,Request request){
        Map<String,String> map = new HashMap<>();
        map.put("hello",name);
        return new JsonResponse(HttpStatus.OK_200,map);
    }

    // POST 请求的Content-Type为multipart/form-data
    @WebPath(value = "/testPost1",method = HttpMethod.POST)
    public Response testPost1(@MultiPartData("photo")MimeData photo,
                              @MultiPartData("name")MimeData name,
                              @MultiPartData("age")MimeData age){
        System.out.println("hello " + new String(name.getData()) + ", your age is " + new String(age.getData()));
        byte[] data = photo.getData();
        try {
            File file = File.createTempFile("the",".jpeg");
            FileOutputStream os = new FileOutputStream(file);
            os.write(data);
            os.close();
            return new FileResponse(HttpStatus.OK_200,file);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return new Response(HttpStatus.OK_200);
    }

    // POST 请求的Content-Type为application/x-www-form-urlencoded
    @WebPath(value = "/testPost2", method = HttpMethod.POST)
    public Response testPost2(@FormParam("name")String name, @QueryParam("age")Integer age){
        System.out.println("hello " + name + ", your age is " + age);
        return new Response(HttpStatus.OK_200);
    }

}
  1. Start Server
import com.light.io.Server;
import java.io.IOException;

public class Application {

    public static void main(String[] args) throws IOException {
        Server server = new Server(); 
        //第二个参数指定扫描@Controller的包名,可以是多个
        server.run(new String[]{"start","localhost:8080"},
                new String[]{"your_controller_pkg_path1","your_controller_pkg_path2"});
    }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].