Skip to content

Latest commit

 

History

History
114 lines (67 loc) · 1.68 KB

README.md

File metadata and controls

114 lines (67 loc) · 1.68 KB

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 [email protected]: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"