Finatra is an open-source project by Twitter that can be used to build REST APIs in Scala programming language. Finatra builds on top of Twitter’s Scala stack — twitter-server, finagle, and twitter-util.
Twitter-server defines a template from which servers at Twitter are built. It provides common application components such as an administrative HTTP server, tracing, stats, etc. These features are wired in correctly for use in production at Twitter.
Finagle is an extensible RPC system for the JVM, used to construct high-concurrency servers. Finagle implements uniform client and server APIs for several protocols, and is designed for high performance and concurrency. Most of Finagle’s code is protocol agnostic, simplifying the implementation of new protocols.
Finagle is written in Scala, but provides both Scala and Java idiomatic APIs.
twitter-util A bunch of idiomatic, small, general purpose tools.
We are discussing here about Finatra version 2 . Finatra version 2 is a complete rewrite of finatra and is significantly faster(50 times according to documentation) than version 1.x.
Why Finatra ??
Finatra2.0 depicts a full rewrite of the codebase from v1.x. In this version, they set out to significantly increase the testability, modularity and performance of the framework. they want to make it easy to work with the codebase as well as intuitive to write really powerful tests for your API.
- ~50x speed improvement over the previous v1.6 release in many benchmarks
- Powerful integration testing support
- Optional JSR-330 style dependency injection using Google Guice
- JSON enhancements supporting required fields, default values, and custom validations
- Fully Async using Futures
- Transport Layer Security(TLS) and Secure Sockets Layer (SSL) support
- Modern logging via SLF4J, Finagle client utilities, and more.
How it is better than others :
- Finatra is a lightweight framework for building fast, testable, scala applications
- Main key point Its testing :
At a high-level, the philosophy of testing in Finatra revolves around the following testing definitions:
- Feature tests — the most powerful tests enabled by Finatra. These tests allow you to verify feature requirements of the service by exercising its external interface. Finatra supports both “black-box” and “white-box” testing against a locally running version of your server. You can selectively swap out certain classes, insert mocks, and perform assertions on internal state. Take a look at an example feature test.
- Integration tests — similar to feature tests but the entire service is not started. Instead, a list of modules are loaded and then method calls and assertions are performed at the class-level. You can see an example integration test.
- Unit tests — these are tests of a single class and since constructor injection is used throughout the framework, Finatra stays out of your way.
Here is code snippet that illustrate the concept:
So, We just covered here what is finatra and what its advantages and how it is better than others REST APIs frameworks . For more better understanding to start with finatra here is an example link hello-finatra that will help you to understand practically. 🙂
Hope it helped you to give a basic idea and start with finatra.
Reference: Finatra
Like it & Share it