EasyRest-NAS
中文文档地址:
EasyRest integration with Netty, Akka and Spring.
This is the high performance RESTful framework, designed for the fast development. Easy to cluster and distributed. You can focus on your business logic.
No tomcat, no web.xml, only need a jar package with 'main' function, you can get a prefect distributed system.
You can don't know Netty, Akka even Spring. You can still using this framework.
Quick start:
The rest definition
@BindURL("/rest/{TENANT}/stock")
public interface StockInfoRest {
@Post("/personal/{USER_ID}/favorite/{CODE}")
void addFavorite(String TENANT, String USER_ID, String CODE, long time);
@Post
ResponseEntity addStocks(int userNumber, String userName, List stockList);
@Get("/personal/{USER_ID}/favorite/list")
List getStockList(String USER_ID);
}
The Service is the bean of spring, you can integrate with spring
@Service
public class StockInfoRestController implements StockInfoRest {
@Override
public void addFavorite(String TENANT, String USER_ID, String CODE, long time) {
System.out.println(TENANT + " " + USER_ID + " " + CODE + " " + time);
}
@Override
@AllDefined
public ResponseEntity addStocks(int userNumber, String userName, List stockList) {
return ResponseEntity.buildOkResponse(Lists.asList(userNumber, userName, new List[]{stockList}));
}
@Override
public List getStockList(String USER_ID) {
return Lists.newArrayList(new Stock(100000, "stock1"), new Stock(100001, "stock2"), new Stock(100002, "stock3"));
}
}
The main class.
public class Example {
public static void main(String[] args) {
EasyRest easyRest = new EasyRest("classpath:MyExampleApplicationContext.xml");
easyRest.startup("EasyRestServer");
}
}
An empty spring config file
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
@BindURL("/rest/{TENANT}/stock") will bind this endpoint at "/rest/{TENANT}/stock"
@AllDefined will check all parameters not be null, if any parameter is null, the framework will reject the request directly.
@Service is spring annotation, that will create bean by spring.