A unix pipe like interace for REST and streaming HTTP APIs.
- Put
bin/hackpipe
into a directory that's in your PATH. - Copy
samples/.hackpiperc
to$HOME/.hackpiperc
and modify it for your APIs
There is a sample ~/.hackpiperc
included in the sample
directory. This should give you a really good overview of what configuration options are available to you.
The top level apis
key holds a hash of each api you wish to configure. The top level alternates
is an array of alternate config files. This is to make it easy to have one api config per file. For example:
alternates:
- ".hackpipe/campfire.yaml" # A config file for the campfire API. Paths are relative to `$HOME`
apis:
github:
# Config for the github API
The "alternate" config files have the same schema as .hackpiperc
, except they do not support alternates.
These examples assume you are using the sample .hackpiperc
Read from the campfire stream:
hackpipe -a=campfire
Post a message to campfire:
echo "Hi Mark!" | hackpipe -a=campfire
Post a Gist to github, and filter the URL only out of the response:
hackpipe < test/github.json -a=github -o='puts JSON.parse(ARGF.read)["url"]'
[test/github.json]
{
"description": "the description for this gist",
"public": false,
"files": {
"file1.txt": {
"content": "String file contents"
}
}
}
Commandline args override the .hackpiperc:
hackpipe -a=campfire -r='node' -o='
process.stdin.on("readable", function(chunk){
chunk = process.stdin.read();
if(!chunk){ return };
console.log(chunk.toString().toUpperCase())
})
'
The input script can modify the request by writing to some special files that are accessible through enviroment varables.
Using the query string global variable:
# the sample .hackpiperc file sets some common query string values for us
# we want to append a few more
hackpipe -a=cmm -e="File.open(ENV['QUERY'], 'a') { |q| q << '&q=marinol' }"
# press ^D, we don't have any stdin to provide
For the auth
key in your ~/.hackpiperc
hackpipe expects you to pre-compute any encoding. For example, many APIs use HTTP Basic auth. For those APIs your auth
value would be the result of:
"Basic " + base64encode("someusername" + ":" + "somepassword")
In otherwords, the value of auth
will be set as the value of the Authorization
header. This makes it easy for hackpipe to support digest, token and bearer auth as well.