Web application
Contents
Introduction
There is a world of difference between a web site and a web application. The former is a static thing--a book. The latter is a tool, a dynamic program--and application.
What is a web application? How do they work? How can you build one? What are the relevant technologies? I attempt to answer these questions here.
HTTP, the Protocol
HTTP, in a nutshell, is a protocol that allows users to ask for data given a URL. It has the following remarkable features:
- The request is made in plain-text, and can contain parameters. For instance, you can say, "Give me this URL, but I want
color=blue
." - The request can be a GET (asking for content) or a POST (asking for the server to accept some data). The difference between the two is that the POST can handle a lot of data, whereas the GET has a limit.
- The server that handles the request is stateless. It knows nothing about the request except the request itself.
The way a client and server interact is something like the following dialog.
- Client: Give me page x.html.
- Server: Here you go.
- Client: Now give me page y.html, with color=blue.
- Server: Here you go.
- Client: Now give me page y.html, with this file attached.
- Server: Here you go.
That's pretty much what is going on.
The Web Server
Next stop is the web server. The web server comes in many forms, depending on which one you want to use. However, all web servers speak the same HTTP language.
Web servers, usually by default, serve up static data. They take a URL, map it to a file, and serve up that file. This allows you to throw together a web site with relative ease. Just put some files in the right places, and away you go.
Web servers can also do a lot of magic. When the client asks for a page, it can go and run a program and dynamically generate the result. This could be a page that shows the current time in London. Or it could be a page that shows all of your email in your inbox.
Understanding this is the foundation for building a web application.
Web Application, No Javascript
The first attempt to build a web application relies on how links in HTML are handled. The pages are delivered to the client, and there are some links and some buttons. The buttons and links, when clicked, merely request a new page, perhaps with some parameters attached. These pages are not files on the file system, but programs. The parameters change the way the programs run, and changes the resulting output. Thus, clicking on links and buttons can get you a pretty good application.
However, the experience is pretty limited. After all, you can do much more than click on text and buttons in your desktop application. Also, the load times are pretty slow--trying to handle a request and generate a page of HTML and then rendering that HTML from scratch is not a quick process, even under the best conditions.
Web Application, With Javascript
Enter Javascript. Using javascript, one can write programs that modify the HTML in place. You can also write programs that respond to the user moving the mouse or clicking on places that aren't links. You can get pretty far with this, but there is still farther to go.
Enter AJAX. AJAX is based on the ability of javascript in the modern browsers to load pages without the user knowing it. These pages are really actions that the user is taking. For instance, if they add an item to a list, the javascript program will load a page to inform the web server that the item has been added to the list.
Pretty funky stuff, and it gets us almost to the point where we can create real applications through the web using HTML, Javascript, and web servers.
However, it is not quite far enough. But for most things, it is pretty dang close.
With HTML 5, you have the canvas element. This allows something like what Flash provides, but at a rudimentary level and in an open format.
Adobe Flash
You can use Adobe Flash on your website. The SWF format is a proprietary, but open, format. For those elements that HTML + JavaScript cannot handle, Flash is the regular replacement.
Microsoft Silverlight
Microsoft has created Silverlight to replace Flash.
Building a Web Application
To build a web application, you need:
- A web server
- A program to handle the requests that the web server receives, and infer state from stateless transactions.
- A database to keep data around.
After that, all you have to do is model your application around the way that web apps work, write a bunch of code to implement it, and verify that it works in the major browsers.