A fast and configurable REST microservices framework for docker containers on the cloud.
Developer Chat | Documentation | Contribution Guide |
Light means lightweight, lighting fast and shed light on how to program with modern Java SE.
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 and other microservices frameworks.
- 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 test stubs are generated 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.
Use your browser/postman to access server endpoints and you will have a generated example message returned if the endpoint has a response body.
Here is a step by step tutorial for example-petstore
And here is a video to show you the steps for above tutorial.
Petstore is a single API, for microservices that involves multiple APIs or services, please follow microservices tutorial
The other way to start your project is to copy from petstore project in light-java-example.
git clone [email protected]:networknt/light-java-example.git
cd light-java-example/petstore
mvn clean install exec:exec
In another terminal, issue the curl command like this to verify the server is working.
curl localhost:8080/v2/pet/111
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.