Fiz: a Component Framework for Web Applications
Total Page:16
File Type:pdf, Size:1020Kb
Fiz: A Component Framework for Web Applications John K. Ousterhout Department of Computer Science Stanford University Abstract Fiz is a framework for developing interactive Web applications. Its overall goal is to raise the level of programming for Web applications, first by providing a set of high-level reusable components that simplify the task of creating interactive Web applications, and second by providing a framework that encourages other people to create addi- tional components. Components in Fiz cover both the front-end of Web applications (managing a browser-based user interface) and the back end (managing the application's data). Fiz makes it possible to create components that encapsulate complex behaviors such as Ajax-based updates, hiding many of the Web's complexities from applica- tion developers. Because of its focus on components, Fiz does not use mechanisms such as templates and model- view-controller in the same way as other frameworks. ger and more useful structures. We will release Fiz in 1 Introduction open-source form and hope to build a user community Although the World-Wide Web was initially conceived that creates an ever-increasing set of interesting com- as a vehicle for delivering and viewing documents, its ponents, which will make it dramatically easier to cre- focus has gradually shifted from documents to applica- ate applications that advance the state-of-the-art in Web tions. Facilities such as Javascript, the Document Ob- interactivity. ject Model (DOM), and Ajax have made it possible to offer sophisticated interactive applications over the The rest of this paper is organized as follows. Section Web. In the future it is likely that more and more of 2 summarizes the intrinsic properties of the Web that the world's interesting applications will be delivered via complicate application development, and Section 3 the Web, displacing the traditional model of installable reviews the most common facilities provided by exist- binaries. ing frameworks. Section 4 presents the Fiz architec- ture, along with the kinds of components it encourages Unfortunately, creating an interactive Web application and some of the infrastructure it provides for creating today is not an easy task. Some of the problems are components. Section 5 summarizes the implementation inherent in the Web, such as the separation between status of Fiz and evaluates Fiz' successes and risks. server and browser, and the numerous languages and Section 6 compares Fiz to other frameworks, and Sec- technologies that must be combined in a Web applica- tion 7 concludes. tion. Other problems come from the development frameworks and libraries available today, which are too 2 Why Web Development is Hard low-level. The result is that application developers There are several factors that contribute to the difficulty spend too much time building complex facilities from of building interactive Web applications: scratch; there are few high-level reusable components • The functionality of a Web application is distributed, available to Web developers, and it is difficult for de- with part running on a server near the application's velopers to carry over code from one application to the data and part running in browsers near the applica- next. tion's users. This paper describes Fiz, a new server-side framework • Web applications must integrate a complex collec- for Web applications. Fiz’ goal is to simplify Web tion of diverse technologies, including HTML [12], development by raising the level of programming: in- Javascript [5], CSS [8], DOM[8], URLs, XML[1], stead of building from scratch, developers create appli- SQL[13], HTTP, SSL, and one or more server-side cations quickly using a library of flexible components languages such as PHP [20], Java [4], Python [11], ranging from high-level objects such as navigation bars or Ruby [6]. Different languages are typically used and tree views down to smaller components such as for server and browser programming. specialized value editors. In addition to its built-in li- • Web applications must support a variety of browsers brary of components, Fiz provides a framework that with feature sets that are still not 100% compatible. encourages the development of new components and • Web applications support multiple users with (what the composition of existing components into even lar- appears to be) a single server. This creates interest- - 1 - Stanford CSD Technical Report, January 9, 2009 ing opportunities for collaboration, but forces devel- CGI programs were quickly replaced by first- opers to deal with problems related to concurrency generation Web frameworks such as PHP [20] and Java and scalability. Popular Web applications must han- servlets [2]. In these frameworks the runtime system dle 100-1000x the workload of traditional applica- for a particular language is bound tightly to the Web tions. server (to avoid the overhead of starting a new process • Web applications must be highly customizable. In for every request) and augmented with Web-specific the pre-Web GUI world a uniform look and feel was library packages that provide features such as the fol- encouraged, but Web applications strive for unique lowing: appearances and behaviors. This makes it more dif- • Parsing incoming URLs and dispatching to an ap- ficult to create reusable components. propriate piece of code for the URL • The public accessibility of Web applications intro- • Interfacing to a variety of backend databases and duces a variety of security and privacy issues, and information sources the complexity of the Web development environ- • Using browser cookies to implement sessions, which ment makes it easy for unaware developers to create store the state for an ongoing interaction with a par- security loopholes such as SQL injection attacks. ticular browser Creating a prototype implementation of a simple Web • Manipulating information in formats such as HTML application may seem easy, but it is a much more diffi- and XML. cult proposition to develop a sophisticated application that is secure, robust, and scalable. Ideally, a good First-generation frameworks also introduced templates component set should help to manage the factors de- to simplify HTML generation. A template is an HTML scribed above, but these factors also make it difficult to document that has been annotated with code in the create such a component set. framework's language. To generate a Web page the template is expanded by replacing the annotations with 3 A Brief History of Web Frameworks HTML computed by the code. The code in the annota- tions can consist of simple variable substitutions, more The features of current Web frameworks arose through complex statements that compute content, or even loop- a series of systems implemented over the last ten years; ing structures that replicate portions of the template this section reviews four major developments that ex- (such as the rows of a table). Templates have become plain the current state-of-the-art. the centerpiece of nearly all Web frameworks. The first Web applications were enabled by the CGI Recent years have seen the arrival of a second genera- (Common Gateway Interface) protocol. Prior to CGI, tion of Web frameworks. These frameworks provide Web servers returned only static files. CGI defined a ORM (Object Relational Mapping) facilities that sim- mechanism that maps certain URLs to executable pro- plify the use of relational databases in Web applica- grams instead of files; for those URLs the Web server tions. One of the best examples of ORM is provided by invokes the executable as a subprocess. The subproc- the Rails framework [21]. Rails associates each data- ess receives the URL as input, generates an HTML base table with a class in the underlying Ruby lan- Web page, and writes the contents of the page to its guage, with one object of the class for each row in a standard output, which is then returned to the request- table and one field of an object for each column of a ing browser. CGI programs are written using a variety row. Rails manages the movement of information be- of languages such as Perl or C++. tween the database and the objects, so Web developers The CGI mechanism is stateless: a new subprocess is can think in terms of the Ruby classes rather than SQL. invoked for each incoming request, and the subprocess Rails also manages relationships between database ta- exits upon completion of the request. If a CGI applica- bles so that they appear as convenient references be- tion needs to maintain state across a series of requests, tween collections of Ruby objects rather than foreign it must store that information in a file or database and keys. Similar ORM facilities have appeared in other reload it for each new request. The stateless property second-generation frameworks such as Django [3], and has become a hallmark of Web applications; although it ORM libraries have been added to some first- complicates application development it improves ro- generation frameworks. bustness (no state is lost if a server machine crashes Second-generation frameworks also introduced a styl- between requests) and simplifies scaling (incoming ized division of labor for Web page generation based requests can be distributed across a cluster of server on the model-view-controller (MVC) paradigm [16,17]. machines without worrying about which one holds the Model classes manage back-end data using the frame- state for that request). work's ORM mechanism. Views are templates that gen- - 2 - Stanford CSD Technical Report, January 9, 2009 erate the final Web page. Controllers provide the glue velopment of higher-level controls for the browser, that ties the pieces together. For example, in Rails each using an approach where developers write in Java, incoming URL is dispatched to a controller, which in- which is then translated automatically to Javascript [9]. vokes models to fetch data for a Web page, then in- Although current frameworks and library packages vokes a view to generate the page's HTML.