Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
bin
 
 
lib
 
 
 
 
 
 
 
 
 
 

Simple HTTP Server

An experiment on building an http server from scratch.

This is a simple HTTP server with minimal features (obviously non spec compliant), built with Ruby using the Socket class available in Ruby’s standard library.

Prerequisites

To run the server locally, you're going to need:

Ruby, I'm running version 2.5.1p57

Getting started

Clone the repo and cd to the working directory

git clone git@github.com:esteedqueen/simple-http-server.git

cd simple-http-server

Start the server

  1. On the default port 4000
bin/start

OR

  1. Specify your preferred port using -p or -port flags
bin/start -p 3000

OR

bin/start -port 8000

Features

Homepage

Test via curl or open in browser:

curl "127.0.0.1:4000/"

OR

open "127.0.0.1:4000/"

Read content of existing file

Test via curl or open in browser:

curl "127.0.0.1:4000/hello.txt"

OR

open "127.0.0.1:4000/hello.txt"

Execute scripts in executable file

Test via curl or open in browser:

curl "127.0.0.1:4000/hello.rb"

OR

open "127.0.0.1:4000/hello.rb"

Query parsing

Store a record: /set?somekey=somevalue

Test via curl or open in browser:

curl "127.0.0.1:4000/set?name=Bolatito"

OR

open "127.0.0.1:4000/set?name=Bolatito"

Retrieve a record: /get?key=somekey

curl "127.0.0.1:4000/get?key=name"

OR

open "127.0.0.1:4000/get?key=name"

Handle file not found

Test via curl or open in browser:

curl "127.0.0.1:4000/hello.py"

OR

open "127.0.0.1:4000/hello.py"

About

A simple HTTP server with minimal features built with Ruby

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published