Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 598f761
Showing
3 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
PREFIX = /usr/local | ||
BIN = burl | ||
|
||
install: | ||
cp -f bin/$(BIN) $(PREFIX)/bin/$(BIN) | ||
|
||
uninstall: | ||
rm -f $(PREFIX)/bin/$(BIN) | ||
|
||
.PHONY: install uninstall |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
# Better curl(1) | ||
|
||
`burl(1)` is a tiny shell script augmenting `curl(1)` with some helpful shortcuts | ||
to make your day a little bit better. | ||
|
||
## Installation | ||
|
||
$ make install | ||
|
||
## Optional hostname | ||
|
||
By default `burl(1)` will assume "http://localhost:3000", however you | ||
can alter this by exporting `BURL` in your terminal session: | ||
|
||
``` | ||
BURL=http://site-im-testing.com | ||
$ burl /pathname | ||
``` | ||
|
||
## -j, --json DATA | ||
|
||
__POST__ data as "Content-Type: application/json": | ||
|
||
``` | ||
$ burl -j {"name":"tobi"} http://local/user | ||
``` | ||
|
||
## Expressive header fields | ||
|
||
With `burl(1)` you can define header fields without `-H`: | ||
|
||
``` | ||
$ burl If-None-Match etag /users | ||
$ burl If-None-Match etag Accept: application/json /users | ||
``` | ||
|
||
## Accept shorthand | ||
|
||
Currently `.json`, `.text` and `.html` shorthands are | ||
available and set the Accept header field for you: | ||
|
||
``` | ||
$ burl /users | ||
$ burl /users .json | ||
$ burl /users .text | ||
$ burl /users .html | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/env bash | ||
|
||
args= | ||
debug= | ||
BURL=${BURL:-http://localhost:3000} | ||
ws="[[:space:]]" | ||
|
||
# | ||
# output usage | ||
# | ||
|
||
usage() { | ||
cat <<EOF | ||
Usage: burl [options] <url> | ||
Options: | ||
-j, --json <data> issue an application/json request | ||
Examples: | ||
$ burl /users | ||
$ burl /users .json | ||
$ burl /users .text | ||
$ burl /users .html | ||
$ burl /search?query=foo | ||
$ burl --json '{"name":"tobi"}' /user | ||
$ burl Accept: application/json /users | ||
$ burl If-None-Match: etag /users | ||
$ burl -X GET --json '{"query":"something"}' /search | ||
EOF | ||
} | ||
|
||
# parse args | ||
|
||
while test $# -ne 0; do | ||
arg=$1; shift | ||
case $arg in | ||
--debug) | ||
debug=1 | ||
;; | ||
-j|--json) | ||
json=$1; shift | ||
curl="$curl -H 'Content-Type: application/json' -d '$json'" | ||
;; | ||
*:) | ||
val=$1; shift | ||
args="$args -H \"$arg $val\"" | ||
;; | ||
/*) | ||
args="$args $BURL$arg" | ||
;; | ||
.html) | ||
args="$args -H Accept:text/html" | ||
;; | ||
.txt|.text) | ||
args="$args -H Accept:text/plain" | ||
;; | ||
.json) | ||
args="$args -H Accept:application/json" | ||
;; | ||
-h|--help) | ||
usage | ||
exit | ||
;; | ||
*) | ||
if [[ $arg =~ $ws ]]; then | ||
args="$args \"$arg\"" | ||
else | ||
args="$args $arg" | ||
fi | ||
;; | ||
esac | ||
done | ||
|
||
test $debug && echo "curl $args" | ||
eval "curl $args" |