#Knod
Knod is a lightweight HTTP server designed to facilitate front end development when the corresponding back end is missing or incomplete. It responds to GET, PUT, POST, PATCH, and DELETE, serving up, writing to, and deleting from the directory of your choosing. Knod has no dependencies outside of the Ruby standard library.
Installation
Ruby 2.1 and above:
gem install knod
Older versions of Ruby:
gem install knod -v 0.4.4
(does not support PATCH)
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.
GET requests map suffixes into MIME types. Data is considered to be application/octet-stream
if the content type is unrecognized.
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}"
.