Exploring the Scala Macro System for Compile Time Model-Based Generation of Statically Type-Safe REST Services - Filipe Rui Rocha Oliveira (2015)
The amount of web services has increased dramatically over the past years due to the growth of mobile applications that use them, and to the business potential that they offer (e.g. Google Maps API, Facebook API). REpresentational State Transfer (REST) is a prolific architectural style used as an interface to these web services, mainly due to its better performance (when compared to other techniques like SOAP), scalability and simplicity. Some common usages of this style include the simple manipulation of structured data, by using default behaviours that are based on user defined models and which provide default CRUD operations. Known implementations are Django REST framework, Eve, Sails, and the LoopBack framework. These frameworks apply the models' logic in run-time usually using reflection or in-memory data structures, and are commonly written in programming languages that are based on (or at least optionally support) dynamic type systems. Although easier to write and more flexible, such technical choices usually hinder two software quality attributes: performance (due to run-time adaptation) and maintainability (due to absence of compile-time guarantees). Assuming such observations and potential shortcomings, the obvious follow-up would be to explore more efficient (and correct) solutions, by interpreting the models at compile-time using a programming language with a sufficiently powerful static and extendable type system. Scala meets these requirements, while still providing enough flexibility to developers looking for it in this kind of framework. With that in mind the this work aimed to explore the design and implementation of such frameworks using the Scala Macro System. The result of this research was materialized in the Metamorphic framework, which by using a semantically rich DSL is capable of generating an entire application from data storage to services logic. Such generated applications mostly contain components of well known and tested libraries, following either an interface or a model. Evaluation was executed by performing both quantitative benchmarks and qualitative analysis of Metamorphic against other frameworks.