cute-server is a tiny http server, based on netty, that can embedded in your java application. you can use annotations to define http api and implement logic by your own code.
use @UriMapping
and @UriVariable
to define mapping url and variable
public class SimpleMapping {
@UriMapping("/echo")
public String echo() {
return "echo on";
}
@UriMapping("/hello")
public String hello(@UriVariable("name") String name, @UriVariable("age") String age) {
String date= new Date().toString();
String out = String.format("hello name=%s age=%s date=%s.", name, age, date);
return out;
}
}
CuteServer cuteServer
= new CuteServer.Builder()
.withPort(port)
.withHttpRequestProcessor(new UriMappingProcessor().withMapping(new SimpleMapping()))
.build();
cuteServer.start();
mvn clean package
# replace with a openjdk image
FROM registry.cn-hangzhou.aliyuncs.com/zmy-repo/openjdk-jre:openjdk-17-jre
ADD target/cute-server-1.0-SNAPSHOT.jar /app.jar
ADD target/libs /libs
ENTRYPOINT ["java", "-Xloggc:/var/gc.log", "-jar","/app.jar"]
MAINTAINER zhaomingyu
docker build -t myz/cute-server:1.0 .
docker run --name=cute-server myz/cute-server:1.0
curl http://<ip-of-container>:9091/echo
curl http://<ip-of-container>:9091/hello?name=zmy&age=30