A fast and configurable REST microservices framework for docker containers on the cloud.
Developer Chat | Documentation | Contribution Guide |
It is 44 times faster than the most popular microservices platform Spring Boot embedded Tomcat and use only 1/5 of memory. Here is the benchmark results compare with Spring Boot, Nodejs and Golang.
- Plugin architecture for startup/shutdown hooks and middleware components
- Distributed OAuth2 JWT security verification as part of the framework
- Request and response validation against OpenAPI specification at runtime
- Metrics collected in influxdb and viewed from Grafana Dashboard for both services and clients
- Global exception handling for runtime exception, api exception and other checked exception
- Mask sensitive data like credit card, sin number etc. before logging
- Sanitize cross site scripting for request header and body
- Audit to dump important info or entire request and response.
- Body parser to support different content types
- Standardized response code and messages from configuration file
- Externalized configuration for all modules for dockerized environment
Design OpenAPI specification and generate the service from it. The specification is also part of the framework to drive security verification and request validation.
Unit/End-to-End tests to enable test driven approach for quality product.
Debugging within IDE just like standalone application for better developer productivity
Dockerfile and DevOps supporting files are generated to support dockerization
OAuth2 server and Portal are working in progress for future production monitoring and management.
There are two ways to start your project:
If you have OpenAPI/Swagger specification, then you can use swagger-codegen to generate a working project. This is the recommended way to start your REST API project. Here are the steps:
git clone https://github.com/networknt/swagger-codegen
cd swagger-codegen
mvn clean install -DskipTests
java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i http://petstore.swagger.io/v2/swagger.json -l light-java -o samples/server/petstore/mypetstore
cd samples/server/petstore/mypetstore
mvn install exec:exec
Please replace the input spec and output folder accordingly.
The server is up and running on port 8080 by default and OAuth JWT verification is off by default.
User your browser/postman to access your endpoints and you will have a message returned.
Here is a video to show you the steps to use generator to start your project.
https://www.youtube.com/watch?v=xSJhF1LcE0Q
The other way to start your project is to copy from petstore project in light-java-example.
mvn clean install exec:exec
To run/debug from IDE, you need to configure a Java application with main class "com.networknt.server.Server" and working directory is your project folder. There is no container and you are working on just a standalone Java application.
create a Java application that main class is com.networknt.server.Server and working directory is your project root folder. You can debug your server just like a single POJO application.
mvn exec:exec
java -jar target/demo-0.1.0.jar
you can use Ctrl+C to kill the server but for production use the following command
kill -s TERM <pid>
The server has a shutdown hook and the above command allow it to clean up. For example, complete in-flight requests and close the database connections etc.