Project

knod

0.14
No commit activity in last 3 years
No release in over 3 years
An http server built using Ruby's standard library
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 10
 Project Readme

#Knod

Gem Version Build Status Code Climate

Knod is a simple HTTP server for prototyping rich JavaScript apps. It responds to GET, PUT, POST, PATCH, and DELETE, serving up, writing to, and deleting from the directory of your choice. Knod has no dependencies outside of the Ruby standard library.

Installation

gem install knod

Usage

The Knod gem comes with an executable; you can run it from the command line with knod. Knod will default to port 4444 and the current directory. You can change these with command line arguments (-p and -d, respectively).

You can also run it by requiring knod and calling Knod.start. Knod accepts an options hash that lets you change the port, root directory, and logging:

options = {port: 1234, root: './some/directory', logging: false}
Knod.start options

Logging is enabled by default. The server will select an open ephemeral port at random if you pass in 0 as the port.

Knod sanitizes the path on all requests and does not allow access to folders outside of the root directory where it is run.

If the path for a GET request is a file, file will be mapped to its MIME type based on the file suffix. Data is considered to be application/octet-stream if the content type is unrecognized. If the path for a GET request is a directory, Knod will concatenate the contents of all files in the directory into a JSON array.

All data from PUT, POST, and PATCH requests is stored as JSON. If the pathway specified in the request does not exist, Knod will create it.

POST requests auto-increment in the specified path and return the id of the file written as JSON (e.g if a POST request led to the server writing 56.json, the server would respond with "{\"id\":56}".