# sardine **Repository Path**: eway/sardine ## Basic Information - **Project Name**: sardine - **Description**: 高性能微服务框架 —— 沙丁鱼,小而迅速,多而勇猛。 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 23 - **Created**: 2015-06-23 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README #Sardine > 本项目是 Netty5+Java8 的 [Sinatra](http://www.sinatrarb.com) 实现。整个项目未完成,尚处于开发中,敬请期待。。。 ##简介 ###超轻量级的Java 微服务框架 - Java8:函数式、Lambda表达式、Stream流式操作 - Netty5:事件驱动、异步高性能、高可靠性 - 极简:全部源码只有100k+,仅依赖netty ###一行代码启动一个Http 服务 ``` public static void main(String[] args) { get("/", () -> "hello sardine."); } ``` **Done!** 现在,打开您的浏览器: >http://localhost:9527/ ##入门 ###依赖 netty ###Server port get/post/header/put/delete ###Route ``` get("/", (request, response) -> { // .. Show something .. }); post("/", (request, response) -> { // .. Create something .. }); put("/", (request, response) -> { // .. Update something .. }); delete("/", (request, response) -> { // .. Remove something .. }); ``` ###3、Request ``` request.host(); request.port(); request.method(); request.path(); request.scheme(); request.contentType(); request.accept(); request.ajax(); request.headers(); request.header("foo"); request.cookies(); request.cookie("name"); request.params(); request.param("foo"); request.paramOptional("foo") request.paramOrElse("foo") request.splats() request.splatsAsList() request.splatFirst() request.splatLast() request.queryParams(); request.queryParam("foo"); request.multiQueryParams("foo"); request.body(); request.bodyAsByte(); request.bodyLength(); ``` ###4、Response ``` response.status(404); response.header("foo", "bar"); response.cookie("foo", "bar"); response.contentType("application/json"); response.body(); response.body("are you ok ?"); response.redirect("/login"); response.file("/hello.html"); ``` ###4、Cookie ###5、Halt ``` halt(); halt(403); halt("a u ok?"); halt(503, "i got u!"); ``` ###6、Filter ###6、redirect ###6、rewrite ###6、exception ###4、static assets ``` staticFileLocation("/resources"); externalStaticFileLocation("/var/www/resources"); ``` ###4、ResponseTransformer json ###4、mvc ###4、gzip ###4、日志 ###4、监控 ###1、HelloSardine 最简版: ``` import static sardine.Sardine.*; public class HelloSardine { public static void main(String[] args) { get("/", () -> "hello sardine."); } } ``` > Run:http://localhost:9527/ Java8 语法糖版: ``` import static sardine.Sardine.*; public class HelloSardine { public static void main(String[] args) { get("/", new HelloSardine()::hello); } public String hello() { return "hello sardine"; } } ``` > Run:http://localhost:9527/ ``` import static sardine.Sardine.*; public class HelloSardine { public static void main(String[] args) { get("/", HelloSardine::hello); } public static String hello() { return "hello sardine"; } } ``` > Run:http://localhost:9527/ #实例 ##Demo工程 ##真实案例 不蒜子: ##压力测试 ab ###参考资料