littlefork-http v1.0.0-rc.1
The Littlefork HTTP.
Wrap littlefork around a HTTP API.
Installation
git clone git@gitlab.com:littlefork/littlefork-api.git
cd littlefork-api
npm installThe littlefork API is configured using environment variables. It's possible to
configure options in a local file, .env. This file will not be added to
the git repository, an entry in the .gitignore prevents that.
cp .env.example
cat .env // Edit as necessaryLF_API_PORT:: The port to listen on. Defaults to 6667.LF_API_DATA_DIR:: The path to the storage directory. Defaults to./data.LF_API_KEY:: The api key that should be sent in a header to auth the request
Usage
To simply run the API, start the server: npm run server. This starts a
server on the port defined in the environment as LF_API_PORT.
There are local targets to run the linting, documentation building and unit
testing. Simply start a development setup: npm run dev.
The package exports the server as a binary. Add littlefork-http as a
dependency and run the server:
$(npm bin)/littlefork-httpDocumentation
To build the latest version of this readme run: npm run docs:api. This
rebuilds this readme file.
The HTTP routes are documented as well. To build them run: npm run docs:rest.
This will build HTML documentation for the HTTP routes. They can be found in
docs/rest.
firefox docs/rest/index.htmlTo build all docs, run: npm run docs.
Development
All functions are curried:
read('path/to/dir', 'project'); // =
read('path/to/dir')('project');curl test:
curl -v -H "apikey: haha" http://localhost:8666/projects
fs-db
read
Read a file and return it as parsed JSON.
read :: String -> String -> Future Json
Parameters
Returns Promise<Object> The parsed JSON that was read from the file.
init
Initialize a node.
init :: String -> Future ()
Parameters
pString The path of the node.
Returns Promise<Null> Returns Unit, pure side effect.
write
Write data into a node. Initialize the node recursively if it doesn't exist.
write :: String -> String -> {} -> Future ()
Parameters
Returns Promise<Null> Returns Unit, pure side effect.
readNode
Read a node for all data and sub nodes.
readNode :: String -> Future [[Object], [String]]
const [fs, ds] = readNode('data/projects');
// fs => [{...}, {...}]
// ds = ['other', 'nodes']Parameters
pString The path of the node.
Returns Promise<Array<Array<Object>, Array<String>>> Returns an array tuple with the first element being a list of data units, and the second element a list of sub nodes.
list
List the data in a node.
list :: String -> Future [Object]
Parameters
pString The path of the node.
8 years ago
8 years ago