Introduction to the Jooby Framework
Want to learn more about the Jooby framework? Check out this post to learn more about Jooby features and whether to incorporate it in your next Java project.
Join the DZone community and get the full member experience.
Join For FreeWhy Java? Why Jooby?
Do you think Java is slow? I want to change your mind. Let‘s take a look!
I check the Techempower benchmarks once every three months. But this month, I was surprised by what I found. You know that the Java platform is very fast and often after integrating C and C++, the Java platform is faster than others. But this time, I saw a micro framework as well as faster of such as raws servlet.
Java has a lot of frameworks, microframeworks, and platforms, as well as libraries. In the last year, we saw a lot of scalable, fast frameworks and microframeworks for Java. But, do you know anything about Jooby?
In this article, we talk about Jooby and the reason why you should test and use it in your project.
What Is Jooby?
Jooby is a scalable, fast, and modular micro web framework for Java and Kotlin.
Jooby follows the basic concept: “do more, more easily” — so, for example, annotations and dependency injection are reduced to a minimum and completely optional in a few areas. Thanks to the use of the JVM Bootstrap in the standard deployment mode, developers can furthermore be shown a way out from the “classpath abyss.”
Built by developer Edgar Espina, Jooby offers modular, stateless application development leveraging NIO (non-blocking IO) servers, including Netty, Jetty, or Undertow.
In this article, we’ll learn what options Jooby offers when it comes to building large-scale web applications and its features.
What Is a Microframework?
A microframework is a term used to refer to minimalistic web application frameworks. It is contrasted with full-stack frameworks. It lacks most of the functionality that is common in a full-fledged web application framework, such as:
- Accounts, authentication, authorization, and roles
- Database abstraction via an object-relational mapping
- Input validation and input sanitation.
- Web template engine
Typically, a microframework facilitates by receiving an HTTP request, routing the HTTP request to the appropriate controller, dispatching the controller, and returning an HTTP response. Microframeworks are often specifically designed for building the APIs for another service or application.
Microframeworks and the Jooby Framework
- You have a template engine
- Multiple ORM
- Security (accounts, authentication, and more)
- Input validation
So, is Jooby a microframework? I don’t think so. Actually, in Jooby, all objects are a module, and you can use them in your project.
Jooby: Features
- Easy to learn
- Simple and effective programming model for building small and large-scale web applications
- Scalable, stateless application development
- Scripting programming model, like express.js, Sinatra
- Built with developer productivity in mind
- Plain Java DSL for routes (no XML or similar languages)
- Reflection, annotations, and dependency injections are kept to a minimum, and in some cases, they are completely optional
- No classpath issues — the default deployment model uses a normal JVM bootstrap
- MVC routes and Script routes
- Multi-protocol: HTTP, HTTPS, HTTP 2.0, Web-Socket
- Multiple API tools for creating an API documentation
- Database Access Module for SQL and NoSQL
- JDBC Access for Relational Database
- NOSQL
- Asset Management for creating your front end for nodes and resources
- Template Engine to create your view and parsing it
- Important Section: Reactive and Async
- Session(Default)
- GUAVA Session Store
- CASSANDRA Session Store
- COUCHBASE Session Store
- REDIS Session Store
- MONGODB Session Store
- Security
- Multiple ways for deployment
- Servers
- Netty— an asynchronous event-driven network application framework
- Undertow— a flexible performant web server written in Java
- Jetty— provides a web server and javax.servlet container, plus support for HTTP/2 and many other integrations
- Servlets — deploy into a servlet container
- Other modules:
- Language support
- Kotlin
- Web services
- AWS
- Consul
- Job scheduling
- quartz
- Full-text search
- Elastic Search
Code Quality
Code quality is the only way to build rock-solid software. We took code quality very serious in Jooby with more than 4000 tests and a code coverage of 99.5 percent.
You can check it out for yourself on GitHub.
Jooby Benchmark
To learn more about performance in Jooby, check out these links below:
This is the benchmark in my server for hello world:
ab -n 10000 -c 100 http://172.16.0.6:8080/
This is ApacheBench, Version 2.3 <$Revision: 1757674 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 172.16.0.6 (be patient)
Completed 1000 requests
Completed 2000 requests
Completed 3000 requests
Completed 4000 requests
Completed 5000 requests
Completed 6000 requests
Completed 7000 requests
Completed 8000 requests
Completed 9000 requests
Completed 10000 requests
Finished 10000 requests
Server Software:
Server Hostname: 172.16.0.6
Server Port: 8080
Document Path: /
Document Length: 9 bytes
Concurrency Level: 100
Time taken for tests: 3.351 seconds
Complete requests: 10000
Failed requests: 0
Total transferred: 860000 bytes
HTML transferred: 90000 bytes
Requests per second: 2984.59 [#/sec] (mean)
Time per request: 33.505 [ms] (mean)
Time per request: 0.335 [ms] (mean, across all concurrent requests)
Transfer rate: 250.66 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 2 15 2.7 16 23
Processing: 5 18 9.2 17 120
Waiting: 5 17 9.0 16 118
Total: 7 33 7.9 32 124
Percentage of the requests served within a certain time (ms)
50% 32
66% 33
75% 33
80% 34
90% 35
95% 36
98% 55
99% 76
100% 124 (longest request)
Run Your Application
A Jooby app looks like this:
public class App extends Jooby { // 1.
{
// 2. add a route
get("/", () -> "Hello");
}
public static void main(String[] args) {
// 3. run my app
run(App::new, args);
}
}
1) Create a new app extending Jooby
2) Define your application in the instance initializer
3) Run the application.
Conclusion
Jooby makes Java web development easy and fun. It has good documentation, and you can run your web application quickly and easily. Readability became an important measure of the quality of programs, with readability in Jooby code being very high.
Also, Orthogonality is one of the important factors in Jooby. Moreover, it’s simple, expressive, effective, and of course, has great performance, so it can keep you safe by using a worker thread.
Jooby provides all the tools to make you more productive, such as hotreload, browser live reload, unit/integrations test, and lots of modules. Additionally, the number of lines required to build something is usually smaller than any other Java framework.
You can join the Jooby channel here.
Opinions expressed by DZone contributors are their own.
Comments