Skip to content

Instantly share code, notes, and snippets.

@jennielees
Created May 8, 2015 00:08
Show Gist options
  • Save jennielees/26d9449099ad215c5f4e to your computer and use it in GitHub Desktop.
Save jennielees/26d9449099ad215c5f4e to your computer and use it in GitHub Desktop.
Web Challenge

Web Challenge

The main job of a web server is to listen on a specific port, handle incoming requests for URLs and figure out what to return back.

Iteratively build up your own web server. We'll be doing some of this together in class, but you can get a head-start and a deeper understanding!

A first step would be to write a program that runs on the command line and listens via raw_input for a user-typed keyword. It then looks up a HTML file in a directory depending on the keyword entered, and returns the text of that file back. The interaction would look something like this:

Welcome to my web server! Enter the route you want:
index
Here is index, served from files/index.html:
<html><head>...etc...</html>

Can you get creative by handling arguments (e.g. index?name=Bob)? Could you insert contents into the HTML before printing it out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment