Introduction

Serving static files through HTTP is not a difficult task. Every little web developer is doing it. But not many people understand the real action that is happening underneath. HTTP protocol is very simple to understand and needs to be understood by everyone as it is one of the most used protocols in the world wide web.

Working of HTTP

The working of the protocol is very simple. It works on the basis of the request and response. A client (generally a user’s browser) makes a request for a particular file and the server it. There are 4 basic types of requests: GET, POST, PUT and DELETE. GET is the most used type of request. When a URL is entered into the browser, the browser makes a GET request to the server. The server serves the required HTML file and the browser renders it.

But for this, we need to have a server which is capable of accepting requests and processing them. There are several tools available to make a simple HTTP server. We are going to have a look at some of them today.

Tools for creating an HTTP server

  • Apache
  • SimpleHTTPServer
  • NGinX

Apache

Apache is the oldest way to render files through HTTP. It is generally used with PHP to make websites. There are two ways to start an Apache server, either through CLI or using a GUI client like XAMP or WAMP.

But the thing about Apache is, it requires you to place all the files you want to serve into a folder called WWW inside the directory where Apache is installed. This is not very convenient if you want to create a server on your own personal machine.

SimpleHTTPServer

This is an HTTP client that comes built in with python. I personally use it when I need to serve a static backendless website/webapp. This can be used to serve any directory on the computer on HTTP. And only that particular directory and its sub-directories are served. 
This can only be used on CLI. But the command to run it is very simple: python -m SimpleHTTPServer

NGinX

NGinX, pronounced as “engine x” is a very powerful Python library capable of not just creating HTTP servers but also proxy servers and email servers. It is very powerful and is used widely. It requires a configuration file for specifying details of the HTTP server.

Little more about HTTP

Creating an HTTP server under some specific directory means, you will be serving all the files under that directory over a particular network. These files can be accessed viewed/downloaded by anyone on that network(except if there is some kind of an authentication system). 
Hope this below average blog post helped you in some way. If you know of any other good HTTP clients, please do mention them in the comments below.

 

Categories: Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *