Towards an MDA Mechanism for RESTful Services Development Christoforos Zolotas Andreas L. Symeonidis Electrical and Computer Engineering Dept. Electrical and Computer Engineering Dept. Aristotle University of Thessaloniki Aristotle University of Thessaloniki GR541 24, Thessaloniki, Greece GR541 24, Thessaloniki, Greece Email: christopherzolotas@issel.ee.auth.gr Email: asymeon@eng.auth.gr Abstract—Automated software engineering research aspires the Model Driven Architecture (MDA) [8], which as a Model to lead to more consistent software, faster delivery and lower Driven Engineering instance shifts the focus of the developer production costs. Meanwhile, RESTful design is rapidly gaining from programming language code to models and transforma- momentum towards becoming the primal software engineering paradigm for the web, due to its simplicity and reusability. This tions. The main goal of MDA is to raise the level of ab- paper attempts to couple the two perspectives and take the first straction, keeping the developer sheltered from implementation step towards applying the MDE paradigm to RESTful service details, thus allowing him to focus on the real problem at development at the PIM zone. A UML profile is introduced, hand. MDA development comprises the following phases also which performs PIM meta-modeling of RESTful web services depicted in figure 1: abiding by the third level of Richardson’s maturity model. The profile embeds a slight variation of the MVC design pattern to 1) Introduction of the Computation Independent Model capture the core REST qualities of a resource. The proposed (CIM), which identifies the abstract domain entities profile is followed by an indicative example that demonstrates without any design or implementation details how to apply the concepts presented, in order to automate PIM production of a system according to MOF stack. Next steps include the introduction of the corresponding CIM, PSM and 2) Transformation of the CIM into the Platform code production. Independent Model (PIM), which introduces the Index Terms—Model Driven Engineering; RESTful services; abstract design of the envisioned system, without any UML Profiles; Meta-modeling; Automated Software Engineering implementation details 3) Transformation of the PIM into the Platform Specific I. I NTRODUCTION Model (PSM), which is an instance of the PIM enriched A. Core Technologies with concrete implementation details The Representational state transfer (REST) architectural 4) Finally, production of software code from the PSM style, exhibits four principal design attributes [2]: This paper aims to take the first step towards applying 1) The Resource Oriented design, which models each con- the MDA paradigm to RESTful web services development in cept as a resource that is addressable with a unique URI order to achieve increased automation, consistency, and faster 2) The various types of representations a resource may have delivery of quality code. It attempts to overcome deficiencies 3) The usage of HTTP as a web API that offers a uniform of other relevant approaches and introduces a UML profile interface for all resources serving as a meta-model for the PIM of a RESTful web 4) The hypermedia, the “engine of application state”, which service. This proposed meta-model, coupled with the related is the semantic interweaving of related resources. meta-models for CIM, PSM and code templates, define the Once these co-exist, the produced web service falls into the essential infrastructure to accomplish automation in RESTful third level of Richardson’s maturity model [3] (RMM). Prac- service development. tically, these design principles allow the simple, yet efficient REST technology to gain acceptance and a bigger share of B. UML Profile Context the programmable web. However, development of RESTful This paper describes a UML profile that is a part of the auto- web services, just like any other kind of software, is prone to mated software engineering strategy followed within project S- the common pitfalls of the established software engineering CASE, an EU funded project for automating RESTful services practices that may lead to project failure, late delivery, high [1]. S-CASE is a cloud based software framework aiming to costs or inability to serve the goals they were built for. facilitate fast RESTful web service prototyping and delivery Aiming to reduce such risks, the Object Management Group by providing the core capabilities depicted in figure 1. Firstly, (OMG) announced at the beginning of the previous decade multi-modal input is provided to the S-CASE engine such a new development paradigm towards increased automation, as software functional requirements, analysis class diagrams, Semantic Parsing and Model Driven Architecture RESTful order to facilitate development of RESTful services through Multi-modal Input Software Entities CIM PIM PSM Code Service Prototype the IDE. Taking the problem from the applied to a more Generator Generator Generator Generator Extraction generic level, S. Shreier [12] attempted to create an initial version of a meta-model for RESTful services using as basis Fig. 1. S-CASE main phases of RESTful services production the Ecore meta-model which is based on the EMOF of OMG. There are also numerous other frameworks that attemp storyboards etc., which are then processed semantically in to model RESTful service but they either do not include order to extract any involved software entities. These entities hypermedia generation or they are semi-automated. Hence, are provided as input to the MDE component, which then this paper presents a meta-model to support third level web outputs the CIM of the service to be produced. Once the services in regard to RMM. CIM is produced, the MDE component traverses through the III. M ETAMODELING REST FUL S ERVICES aforementioned MDA phases, from CIM to PIM, PIM to PSM A. Grounding Definitions and PSM to code by means of model transformations. Within the context of this paper the focus is on the MDE Before discussing the extended UML meta-model for REST- component (highlighted) and more specifically on the UML ful services, the way the PIM versus PSM on the MOF layer profile serving as the S-CASE engine PIM meta-model. As stack are conceptualized within this paper must be clarified; already mentioned (and later explained), the UML profile hence follow two definitions: ensures that the semi-automatically produced system has all D1: A target platform is the combination of all concrete the core design attributes of the REST style alongside some technologies and designs used to form a system. PSM useful design properties, such as seperation of interfaces from refers to such a platform. their implementations and uniform access to databases. D2: A platform independent system is formed by the com- bination of technology abstractions and abstract design C. Paper Structure paradigms. PIM refers to such an abstract platform. The structure of this paper is as follows. Section 2 discusses For example the HTTP verbs POST, READ, PUT, DELETE relevant work. Section 3 presents the proposed UML profile are the realization of the abstract CRUD verbs. Hence, the pre- with its constraints. Section 4 illustrates automated PIM pro- sented meta-model uses the concept of CRUD verbs instead. duction of a social media application. Section 5 summarizes the work performed, probes on future work and concludes the B. The UML Profile Key Features paper. This subsection presents a (simplified) meta-model of the REST concepts and database schemas that frequently accom- II. BACKGROUND - R ELEVANT W ORK pany web services. A UML profile mechanism [4] is employed MDE has been applied to several domains and has received that allows varying the meaning of UML meta-model by both appraisal (higher productivity, increased formalism and applying to it stereotypes, tags and constraints. This profile increased automation) and criticism (complexity of modeling is depicted in figure 2. itself, varying automation and often mostly for code genera- The profile definition begins by modeling the resource, tion, lack of coherence among MDE tools, etc) [7]. Thus, while which is the core of a RESTful service. Abiding by the one may argue that MDE cannot be considered a “panacea” separation of concerns approach followed by the MVC pattern, for software development, the simple, unambiguous design the Model Representation Controller or MRC pattern of a concepts of REST, as discussed in the introductory section of resource is introduced. According to MRC, a resource com- this paper, predispose for succesful application of the MDA prises a ResourceModel that encapsulates resource data, some paradigm on REST applications. ResourceRepresentations each of which has a MediaType tag, Related work regarding MDE for the RESTful services and a ResourceController that has a unique URI and exposes domain mainly focuses on the introduction of approaches the resource’s uniform interface. to capture RESTful services with annotated description lan- This interface is modeled by extending the UML meta- guages. Such efforts include work by Kopecky et al. that class “operation” with the stereotype CRUDActivity. Since introduce hREST [5], Maleshkova et al. that extend SAWSDL there are four discrete CRUD verbs a CRUDActivity can to annotate RESTful services as well [6], and Pagliarecci et al. be of type CreateActivity, ReadActivity, UpdateActivity or that introduce SWSAL [10]. One should also mention work DeleteActivity to match the meaning of each CRUD verb. by Tavares et al. [14], who introduced a meta-model for the Every CRUDActivity may have some inputMediaTypes and/or various semantic annotation languages of RESTful services, some outputMediaTypes, according to its type, in order to aiming to achieve increased interoperability among them. The model web communication formats such as XML or JSON. above approaches mainly focus on the semantic annotation The Hypermedia concept of REST is modeled by extending of RESTful services and their characteristics, rather than the the UML meta-class “Association” with the stereotype Relate- software engineering process itself. dResource. This extension intends to model both types of inter- In a more MDE-focused research direction, Ormeno et al. resource relationships. That is, a resource may have related re- [9] aspire to apply MDE to Spring Roo software artefacts in sources, or be related resource of others. The RelatedResource Fig. 2. UML profile for PIM meta-modeling of RESTful services. stereotype has two tags, the uri that links to a related resource D. Meta-model Constraints and the ConditionSet, which is a set of conditions that must be met if the resources are to be considered related. Furthermore, Typically, the presented extensions are accompanied by a to allow the association of a resource’s specific CRUDActivity list of constraints, usually in OCL. Since providing a full list with one of another resource, the RelatedCRUDActivity data of OCL constraints is out of the scope of this paper, this type is added to the profile. This one, apart from the Condi- subsection presents a visualization of them (figure 3). These tionSet and the uri of the related resource, also incorporates the constraints depict which components of the profile may be CRUDActivity to be accessed if the ConditionSet is fulfilled. In associated with which, or composed of, other components. either case, if the Conditions are met, the expected behavior of The core of this meta-model, the resource, comprises a a RESTful service is to embed into the outgoing representation ResourceModel with at least one ResourceRepresentation and all the related URIs that would allow the client to forward the exactly one ResourceController that handles its web requests. application state. The introduced profile models these controls Every such ResourceModel may have some RelatedResources with the HypermediaLink data type, which comprises an href and may be related resource of some others. The Resource- attribute that stores the uri of accessible related resources, a rel Controller handles the requests that must conform to the attribute that describes the relation between the interconnected uniform CRUD API, so it must have one CRUDActivity for resources, and the CRUDVerb attribute that specifies which each CRUD verb of the overlying resource. Since a resource CRUDVerb must be used. can have many representations, a ResourceController must have one CRUDActivity for every input/output media type to C. Business Logic and Uniform Storage be supported and every media type that is to be supported In order to allow separation of concerns, another extension must be of a ResourceRepresentation type that this specific of the meta-class “class” is added to the UML profile, the ResourceModel is associated with. The allowed media types CRUDActivityHandler. This addition aims to gather the busi- per CRUDActivity type are listed in table 1. ness logic of the resource in (CRUDActivityHandlers) and let Moreover, since some resources may be related to non the CRUDActivities handle the high level semantics of the web CRUD verb operations that are not allowed due to the uniform interface. Following the same pattern, there is one type of interface constraint, the Richardson’s [11] design solution is CRUDActivityHandler for each CRUD verb. followed. Thus a new, algorithmic, resource is added with Finally, in order to introduce a uniform storage mechanism, CRUD interface in order to model the initial non CRUD the profile embeds the Repository design pattern with the operation. This case will be further clarified in the example RepositoryController stereotype. This is a dedicated compo- that is presented in the next section. nent to handle the I/O operations with the underlying relational Separating the business logic implementation from the uni- database. The relational database schema is modeled with four form web API as explained earlier, each ResourceController more extensions, the RDBMSTable and Column stereotypes, as has exactly one composition association with a CRUDActivity- well as the PrimaryKey and ForeignKey stereotypes to model Handler for every CRUDActivity it has. In turn, each CRUDAc- the corresponding relational database concepts. tivityHandler accesses the unique RepositoryController of the Fig. 3. Visualized constraints of the UML profile. TABLE I I/O MEDIA TYPES PER CRUDACTIVITY has Resource has CRUDActivity Property -isAlgorithmic? CRUDActivity Input Type Output Type Related Resource CreateActivity Yes Yes - with Condition Set ReadActivity No Yes UpdateActivity Yes Yes Fig. 4. Illustrative CIM meta-model DeleteActivity No No FR4: A user must be able to mark a personal bookmark as system in order to query the underlying database. The Reposi- public or private. toryController must have exactly one RDBMSSelectActivity for FR5: A user must be able to add tags to his/her bookmarks. every ReadActivityHandler that is connected to it and simirarly FR6: Any user must be able to search by tag the bookmarks. one RDBMSInsertActivity for every CreateActivityHandler, one RDBMSDeleteActivity for every DeleteActivityHandler B. From Requirements to PIM and one RDBMSUpdateActivity for every UpdateActivityHan- Producing the CIM is the first step of MDA paradigm. dler. All these handle the low level database querying. The However since this paper focuses on PIM meta-modeling and database comprises of at most one RDBMSTable for every due to space limitations, only an indicative CIM meta-model ResourceModel of the system. Each RDBMStable has one is provided that is proper for the PIM meta-model that is PrimaryKey, none or more ForeignKeys and as many columns presented. as the properties of the respective ResourceModel. This illustrative CIM meta-model (figure 4) comprises re- IV. I LLUSTRATIVE AUTOMATED PIM P RODUCTION sources that can have related resources should a condition set is satisfied. They can be algorithmic or non-algorithmic, as A. The RESTMARKS Application already discussed, and have some properties. Moreover, the This section demonstrates the steps to be followed in order resources may have some CRUD activities, at most one of to automatically produce the PIM of a test application. The each type. application at task is called RESTMARKS, a social media Abiding by this meta-model and taking into account the application that allows users to create and tag bookmarks, or functional requirements, figure 5 demonstrates one possible search its database to retrieve bookmarks that either they own RESTMARKS CIM. In this case there are four resources, or are public bookmarks of other users. In this example it is as- the Account, Bookmark, Tag and TagSearch ones, whilst the sumed that the functional requirements (FR) of RESTMARKS TagSearch is the only non-algorithmic resource. Additionally, are the following: the Account resource has the password and a username prop- FR1: A guest user must be able to create an account by erties(FR1), the Bookmark resource has a URL and scope providing a username and a password. (FR3-FR4) and the Tag one has a textual description prop- FR2: A user must be able to update his/her account. erty (FR5). Moreover, the assigned CRUD activities to the FR3: A user must be able to add, delete, retrieve or update Account resource are the update and create one (FR1-FR2) any bookmark of his/her account. whilst to the Bookmark and Tag ones, all the possible CRUD Create Update Create Read F. Creating the Relational Schema Update Creating the underlying database is the next step, once the Account Bookmark -non Algorithmic Related Resource -non Algorithmic ResourceModels are in place. Thus, for every non algorithmic - no conditions Delete ResourceModel of the PIM, an RDBMSTable is added to it. URL Related Resource Therefore, the tables Account, Bookmark and Tag are added to Password Username Scope - no conditions the RESTMARKS PIM. Subsequently, for each ResourceModel property, a column is added to the respective table. Therefore, TagSearch Tag Description - Algorithmic Related Resource -non Algorithmic the columns username and password are added to the Account - no conditions table, the columns url and scope to table Bookmark so on. Delete Read Create Read Update However, for relational reference, each RDBMSTable must have exactly one primary key. Therefore, a new column as Fig. 5. Illustrative RESTMARKS application CIM a primary identifier is added to each table with the same name as the table, post-fixed with id. Hence the primary key AccountId is added to table Account, and BookmarkId and activities. Finally, figure 5 demonstrates the relations among TagId to tables Bookmark and Tag repsectively. Finally, in the resources. order to achieve consistent mapping among the schema tables and the ResourceModels, one more property is added to each C. Identifying the Resources of them with the same name and type as the primary key of The process begins with transforming the CIM resources to each schema table. Therefore, the property AccountId is added their PIM counterparts, which comprises one ResourceModel to AccountModel, BookmarkId to BookmarkModel and TagId one ResourceController and some ResourceRepresentations. to TagModel. In RESTMARKS case the identified resources are the Account, Establishing proper cross-reference among the interweaved Bookmark, Tag and TagSearch. All these components are resources with foreing keys, is the last step to produce the interconnected as prescribed by the meta-model constraints, database schema. For every resource X that is a related so every ResourceController has a unidirectional association resource of another one Y, the primary key of that table Y with the corresponding ResourceModel, which in turn has a is added as foreign key to the table X. In this case, the foreign unidirectional association with its ResourceRepresentations. key BookmarkId is added to table Tag and the foreign key Once the resources are added to the PIM, their properties AccountId to table Bookmark. are added to the respectiveResourceModels. In this case the AccountModel has the password and username properties, the G. Creating the RepositoryController BookmarkModel has the url and scope and the TagModel has The final step towards PIM production is to create the the description. schema controller so that all CRUDActivityHandlers have access to the persistent storage. Thus, the RDBMSController D. Identifying the Relations Among Resources is added to the system. As prescribed in the profile constraints, The next step is to apply the identified relations among the the RepositoryController must have one RDBMSSelectActivity resources. In RESTMARK’s CIM case, the AccountModel is for every read activity, one RDBMSInsertActivity for every not a related resource of any other resource, but has as related create activity, one RDBMSDeleteActivity for every delete resource the BookmarkModel. Therefore, a RelatedResource activity and one RDBMSUpdateActivity for every update activ- unidirectional association is added from AccountModel to- ity.In this context the createAccount RDBMSInsertActivity is wards BookmarkModel. In the same pattern, figure 6 demon- added and the updateAccount RDBMSUpdateActivity as well. strates the semantic interweaving of all the resources. In a similar manner, the respective RDBMSSelectActivities are defined for the other resources. E. Adding CRUD Verb Activities Once all the above steps are executed, by an algorithm The next step is to add every CRUDActivity that is allowed that conforms to the presented meta-model, the RESTMARKS on a specific CIM resource to the respective PIM Resource- PIM is completed (figure 6). This PIM would then be the Controller. Hence, the CreateAccount and UpdateAccount input to another PSM generation algorithm that conforms to CRUDActivities are added to AccountController and likewise an appropriate for this PIM, PSM. That PSM in turn, would the createBookmark, readBookmark, updateBookmark and contain the needed meta-data for code production based on deleteBookmark CRUDActivities to BookmarkController and code templates. In general, should the MDA paradigm is so on. Moreover, following the meta-model constraints, each followed by using the presented profile, once the developer ResourceController must have exactly one unidirectional com- completes creating the CIM, the rest is automated up to the position association with a CRUDActivityHandler for every PIM creation. Should the PSM and code generation com- CRUDActivity of the same type. Thus, AccountController has a ponents are defined likewise, the PSM and code generation createAccountActivityHandler and an updateAccountActivity- would be semi-automatically produced as well. It must be Handler, while the BookmarkController and the TagController noted though that depending on the case, the completeness of have every type of CRUDActivityHandlers. the produced system may greatly vary and the developer will Fig. 6. RESTMARKS application produced PIM. have to fill in the details that where not described sufficiently [4] L. Fuentes-Fernadez and A. Vallecilo-Moreno. An introduction to uml by the UML profile such as authentication. profiles. The European Journal for the Informatics Professional, 2:6–13, 2004. V. C ONCLUSION AND F URTHER W ORK [5] J. Kopecky, K. Gomadam, and T. Vitvar. hrests: An html microformat for describing restful web services. In WI-IAT ’08, volume 1, pages This paper introduces a RESTful service PIM meta-model 619–625, Dec 2008. [6] M. Maleshkova, J. Kopecky, and C. Pedrinaci. Adapting sawsdl for that aids the semi-automated development of services that semantic annotations of restful services. In On the Move to Meaningful respect REST design qualities, such as resource oriented de- Internet Systems: OTM 2009 Workshops, pages 917–926, 2009. sign with uniform CRUD interface and embedded hypermedia [7] P. Mohaghehi and V. Dehlen. Where is the proof? a review of experi- ences from applying mde in industry. In Model Driven Architecture - links. It demonstrates as well a set of steps to be taken in Foundations and Applications, volume 5095, pages 432–443, 2008. order to produce the PIM of an indicative application called [8] OMG, http://www.omg.org/mda/. Model Driven Architecture, 2000. RESTMARKS.However, it is only one of the steps towards [9] E. Ormeno, M. Lund, L. Aballay, and S. Aciar. An uml profile for modeling restful servicecs. In ASSE 2012, pages 119–133, 2012. applying MDA in RESTful development. Next steps include [10] F. Pagliarecci, L. Spalazzi, and G. Taccari. Application of swsal in the definition of a full MDA mechanism that also includes the semantic annotation of restful web services. In INVIT2012, pages 11– CIM, PSM and code generation steps as well. 18, 2012. [11] L. Richardson and S. Ruby. RESTful Web Srvices. O’Reilly, 2007. Acknowledgments.: Parts of this work have been supported [12] S. Sshreier. Modeling restful applications. In WS-REST 2011, pages by the FP7 Collaborative Project S-CASE (Grant Agreement 15–21, 2011. No 610717), funded by the European Commission. [13] D. Steinberg, F. Budinsky, M. Paternostro, and E. Merks. EMF: Eclipse Modeling Framework. Addison-Wesley Longman, 2009. R EFERENCES [14] N. A. C. Tavares and S. Vale. A model driven approach for the development of semantic restful web services. In IIWAS 2013, page [1] FP7 Collaborative Project S-CASE: Scaffolding Scalable Software Ser- 290, 2013. vices. http://www.scasefp7.eu. [2] R. T. Fielding. Architectural Styles and the Design of Network-based Software Architectures. PhD thesis, University Of California, 2000. [3] M. Fowler. Richardson Maturity Model: steps towards the glory of REST. http://martinfowler.com/articles/richardsonMaturity Model.html, March 2010.