A web application is a computer program that responds to an HTTP request by a client and sends back HTML to the client in an HTTP response. In other words, a web application is a server — a web server, to be exact. The client is usually a web browser, and they communicate over HTTP.
A web service , on the other hand, is a computer program that responds to an HTTP request by a client that is not a browser used by a human user but another computer program. A web service is a server as well, but it usually returns JSON, and it increasingly also returns binary formats.
Parts of a Web Application
A web application generally consists of three parts:
A multiplexer
• A router that matches the request URI to a handler function
One or more handlers
• Functions that handle the requests and return the responses
A template engine
• An engine that combines one or more templates with data and renders the response
The multiplexer is quite straightforward. It simply matches the request URI to a handler according to a URL route. For example, you want to match the URL route /home to a homeHandler function.
The handler function is where the real work is done. It takes in a request, does some processing with the data from the request, and returns a response.
The template engine is used to render the body of the response. It combines one or more templates with data and returns the response body. While this is commonly HTML, it can be any format, including JSON, XML, plain text, or even binary data, such as images and PDFs.