Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Jun 23, 2012
0 parents commit 598f761
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 0 deletions.
11 changes: 11 additions & 0 deletions Makefile
@@ -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
48 changes: 48 additions & 0 deletions Readme.md
@@ -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
```
79 changes: 79 additions & 0 deletions bin/burl
@@ -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"

0 comments on commit 598f761

Please sign in to comment.