Fast, lightweight Web framework based on Netty; without too much dependency, and the core jar package is only 30KB.
If you are interested, please click Star.
- Clean code, without too much dependency.
- One line of code to start the HTTP service.
- Custom interceptor.
- Flexible parameters way.
- Response
json. - Start with
jar. - Custom configuration.
- Multiple routing ways.
- Support
HTTPS. - Support
Cookie. - File Upload.
Create a project with Maven, import core dependency.
<dependency> <groupId>top.crossoverjie.opensource</groupId> <artifactId>cicada-core</artifactId> <version>1.0.1</version> </dependency>
start class:
public class MainStart { public static void main(String[] args) throws InterruptedException { CicadaServer.start(MainStart.class,"/cicada-example") ; } }
Create business Action implement top.crossoverjie.cicada.server.action.WorkAction interface:
@CicadaAction(value = "demoAction") public class DemoAction implements WorkAction { private static final Logger LOGGER = LoggerBuilder.getLogger(DemoAction.class) ; private static AtomicLong index = new AtomicLong() ; @Override public WorkRes<DemoResVO> execute(Param paramMap) throws Exception { String name = paramMap.getString("name"); Integer id = paramMap.getInteger("id"); LOGGER.info("name=[{}],id=[{}]" , name,id); DemoResVO demoResVO = new DemoResVO() ; demoResVO.setIndex(index.incrementAndGet()); WorkRes<DemoResVO> res = new WorkRes(); res.setCode(StatusEnum.SUCCESS.getCode()); res.setMessage(StatusEnum.SUCCESS.getMessage()); res.setDataBody(demoResVO) ; return res; } }
Launch and apply access: http://127.0.0.1:7317/cicada-example/demoAction?name=12345&id=10
{
"code": "9000",
"dataBody": {
"index": 1
},
"message": "ζε"
}Implement top.crossoverjie.cicada.example.intercept.CicadaInterceptor interface.
@Interceptor(value = "executeTimeInterceptor") public class ExecuteTimeInterceptor implements CicadaInterceptor { private static final Logger LOGGER = LoggerBuilder.getLogger(ExecuteTimeInterceptor.class); private Long start; private Long end; @Override public void before(Param param) { start = System.currentTimeMillis(); } @Override public void after(Param param) { end = System.currentTimeMillis(); LOGGER.info("cast [{}] times", end - start); } }
If you only want to implement one of the methods ,only extends top.crossoverjie.cicada.server.intercept.AbstractCicadaInterceptorAdapter abstract class.
@Interceptor(value = "loggerInterceptor") public class LoggerInterceptorAbstract extends AbstractCicadaInterceptorAdapter { private static final Logger LOGGER = LoggerBuilder.getLogger(LoggerInterceptorAbstract.class) ; @Override public void before(Param param) { LOGGER.info("logger param=[{}]",param.toString()); } }
Test Conditions: 300 concurrency for twice ;1G RAM/one CPU/1Mbps.
crossoverJie#gmail.com