# A Model-Driven Method for Fast Building Consistent Web Services in Practice ## David Sferruzza ### 2018-01-23 --- # About me - PhD student in software engineering at *LS2N* (Nantes, France) - Doing *Research and Development* at [Startup Palace](https://www.startup-palace.com)  --- # Web services (WS) > A web service is a software system designed to support interoperable machine-to-machine interactions over a network. It is a software that: - communicates over the network using **HTTP** - transforms **requests** to **responses** using an _executable_ representation of the _business logic_ --- # Why building WS? - _web applications_ deliver services to human end-users - humans communicate with applications through **User Interfaces** (UIs) Sometimes, we need several UIs for the same application. People often separate **data logic** from **UI logic**: - **data logic**: web services (HTTP) - **UI logic**: RIA, Android, ... It is easier to build/test/maintain (separation of concerns), even if there is only one UI. --- # Our context Startup Palace create **web applications** to help its customers to **test** their market hypotheses. - Minimum Viable Product (MVP) - lump sum payment - iterative process + variable specifications → code must be maintainable/reusable Here, we focus on making **web services**. --- # Minimum Viable Product  --- # Motivation Two kinds of features: - _game changers_ - _show stoppers_ We want to **automate** the making of _show stoppers_: _show stoppers_ take a lot of time to humans and are **tedious**. (Humans bring more value when working on _game changers_.) --- # Contributions Building web services using **safe abstractions** on top of **an existing programming language** in order to ease development and **reuse** of _show stopper_ features. - a **meta-model** to express WS - a corresponding semantics for **verification** - a tool to: - **check** models consistency - **generate** working WS --- # The meta-model 1. **Entities**
data model 2. **Components**
parametric and composable units of computation 3. **Services**
exposed HTTP API --- # Components There are 2 kinds of components: - **atomic** - **composite** Every component can have **parameters** that can be used in its implementation or by its children. --- # Atomic component - has preconditions on its execution context - has effects on its execution context - implemented using a programming language ```text ac name CheckKey params (correctKey: String) pre (key: String) ``` --- # Implementation of an atomic component ```php get('correctKey'); $key = $ctx->get('key'); if ($correctKey === $key) return $ctx; else return response('Invalid key', 401); } } ``` --- # Component instance CIs must provide one argument per parameter of the instantiated component. ```text ci CheckKey(correctKey = "mykey") ``` --- # Composite component - defined by a list of component instances (CIs) - inferred preconditions, effects and implementation ```text cc name GetAttendees params (apiKey: String) ci CheckKey(correctKey = apiKey) ci FetchRegistrations ci RegistrationsSerializer ``` --- # Verification The meta-model was designed to allow verification of the **structural** consistency. _For example: verifiying that every component in an assembly of components will be executed in a context which satisfies its preconditions._ - gives confidence in the model (at _design-time_) - without paying the price of specifying everything formally --- # The tool Safe Web Services Generator  - **input**: - model of web services - implementations of the atomic components - **output**: set of files to put in a Laravel web application - command-line program, written in Scala - **dependencies**: Java 8+ --- # Complete example ```text e name Registration attributes (name: String, email: String, date: DateTime) s method GET url \/attendees\/(?
[^\/]+) params (key: String) ci GetAttendees(apiKey = "mykey") cc name GetAttendees params (apiKey: String) ci CheckKey(correctKey = apiKey) ci FetchRegistrations ci RegistrationsSerializer ac name CheckKey params (correctKey: String) pre (key: String) ac name FetchRegistrations add (registrations: Seq(Registration)) ac name RegistrationsSerializer pre (registrations: Seq(Registration)) ``` --- # Conclusion This approach was tested on very small projects: - it was able to **generate** working web services - the tool quickly **caught** several typos and design flaws We are considering to: - add compatibility with _OpenAPI_ - create a GUI to explore models - automate verification of implementation compliance - evaluate the approach on larger projects --- # Questions? Slides:

Article: