# Web Programming/Web and Web Programming
## The Web and the Internet

What is the Web? Known as the World Wide Web the web is an application or service running on the Internet, which is the infrastructure (information superhighway - a delivery mechanism). The Internet is a interconnect global network of computer networks, which is like a postal system which allows us to deliver mail pieces of all kinds with "the web" as one of them. Initially the web is designed to be a distributed hypertext document sharing system. Now it has evolved to become a platform for distributed applications. Think about all the web applications you use, e.g. Google search engine, Amazon web store, and Youtube.

## The Client-server Model

The Web is based on a simple client server model. As shown in the figure a client sends a request and the server responds by sending a response back.
It is a rather simple model, but we can build powerful application with this simple model.
Both clients and servers are software entities but both run on hardware platforms. The same hardware platform can have multiple software entities running on it. Normally a web client is a web browser, e.g. IE, Firefox, or Chrome, and a web server is a server running software like Apache and IIS. The boundary between a web client and a web server is blurred when a web server consumes web services offered by other web servers and hence become a client to them.
Every web application has two components: the client side and the server side. There are programming frameworks (e.g. Google App Engine) available for writing web applications as one piece by automatically generating the client side. We will manually manage the two components to get a better understanding of web basics.

### HTTP

HTTP stands for the Hypertext Transfer Protocol, which is an agreed upon standard (set of rules) for communicating on the web. It is like a language and any program that speaks the language can be a member of the web as a client, a server, or both. Each service that runs on the Internet has its own protocol, such as IMAP for email retrieval, FTP for file transfer, and SNMP for managing networks.

### API

You don't need to master the HTTP protocol in order to create web applications. Web APIs (Application Programming Interface) allows us to focus on the application logic by abstracting away the details of the common tasks (plumbing). As shown in the figure an API provides a higher-level abstraction of the detailed mechanisms.
The browser works as a user agent firing HTTP request on human users behalf. For instance, when a user clicks on a hyperlink the browser sends HTTP request. The request can be a GET request, e.g. fetching a new page, or a POST request sending (form) data to a server. We, as programmer, can also send requests by calling functions (part of API provided by the browser) in the client code, which runs in the browser.

### URL

URL (Uniform Resource Locator) is also known as web address. Any resource available on the Web is identified by an URL, which has to be unique globally.
The following figure shows an example URL pointing to a file (resource) on a web server:
When the URL is sent to the server, the server will map the rest of the URL - /~blu/helloworld.html - to a path in the server's file system: /home/blu/public_html/helloworld.html. In other words, whatever is after /~blu/ gets appended to /home/blu/ to be used to find the resource (file) on the server.

### "Hello World!" Example

In the previous example, if the following text is in the helloworld.html file you would have seen the text appeared in the browser window after you typed in the URL in the address bar and hit enter.
Hello World!
Sending a URL via a browser triggers a GET request to the server for the resource identified in the URL. The response to the request is the content of the file. This is the simplest example showing how the client-server model works.